What is the difference between following a link and calling a link?

What is the difference between passing by reference and calling by reference in java?

+6
java
source share
4 answers

Java does not pass any variables by reference.

It is tempting to think that objects are passed by reference to Java, but are harmful. Object type variables are references. When they are transmitted, they are transmitted by value.

In other languages, passing by reference and calling by reference are one and the same.

Edit: For more information, see the existing stackoverflow question "Passing Java by reference?" (Spoiler: No.)

+9
source share

Important concept. Java has no concept of "pass by reference". Everything in Java is passed by value. When you pass an object reference to a parameter in a method call, what you really do is pass a value that points to your object's reference.

The following URLs explain this in more detail: http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html and http://javadude.com/articles/passbyvalue.htm ? repost

Apparently (as indicated in the comments on your question), the terms โ€œpass by linkโ€ and โ€œcall by linkโ€ mean the same thing.

+7
source share

You asked, but "pass by reference" and "call by reference" is the same.

If you are looking for the difference between passing by reference and pass by value, check the answers to

Pass by reference or pass by value?

But remember that Java passes a parameter by value.

http://javadude.com/articles/passbyvalue.htm

http://academic.regis.edu/dbahr/GeneralPages/IntroToProgramming/JavaPassByValue.htm

+1
source share

What is the difference between passing by value and passing by reference in Java?

In Java, there is no such transfer by reference; everything in Java is passed by Value!

Variables in Java are typed, the JVM needs to know which variables are variables before executing the program, and based on the type it will try to allocate memory to store the value stored in this variable.

Now there are primitive types and objects, primitives have a fixed size (for example, char, byte, int, long, etc.). objects can be something else that groups primitive variables and functions.

In other words, primitives are a variable that contains a value whose type is known and determined by size, and objects is a variable whose value is the memory address of an actual object that has a collection of variables and functions.

Thus, in the context of executing a function, primitives pass a copy of the actual value to the function, and objects pass a copy of the address to the address where the instance is stored, so the objects seem to pass a breakpoint where the actual Object is stored.

The key point is that Java never provides direct access to the values โ€‹โ€‹of the objects themselves under any circumstances. The only access to the specified object is through a link.

0
source share

All Articles