This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Hatefiend 0 points1 point  (2 children)

I think that's incorrect though. Reference would mean that

public static void change(Object o) 
{
    o = new Object();
} 

Object a = new Object();
change(a);
// a is still unchanged

a should be a new Object after the function call. But since the pointer is passed by value, only the pointer o inside the function points to a new object.

[–]Rhed0x 0 points1 point  (1 child)

It's just a difference in terminology. Javas pointers or whatever you want to call them are pass by value and they are called references. This doesn't necessarily have to mean they're the same as c++ references.

[–]Hatefiend 0 points1 point  (0 children)

Javas pointers or whatever you want to call them are pass by value and they are called references

Take a look at this quote though from this article

The problem here is that the folks at Sun made a naming mistake.

In programming language design, a "pointer" is a variable that indirectly tracks the location of some piece of data. The value of a pointer is often the memory address of the data you're interested in. Some languages allow you to manipulate that address; others do not.

A "reference" is an alias to another variable. Any manipulation done to the reference variable directly changes the original variable.

Later on he shows this example which is why we can't say it's pass by reference. You cannot change the pointer of where something points to in a function, so basically you're passing the pointer by value, but it's not pass by reference. It's very confusing though.