> Objects are passed to methods by reference ehile
> primitives are passed by value.
Oh brother, here we go again...
No, EVERYTHING is passed by value. The object reference is passed in by value as well. If the object is mutable, you can call methods on it to change its state. However, that won't work for Double, as Double is immutable anyways.
> is there any means to pass double or Double by
> reference?
No.
The reason for this is because you want to modifiy it?
Then do one of the following...
- The method returns a value, there it is.
- You pass in an array, modify the contents of the array
- Create your own object. Pass it in. Modify the contents.
> > Objects are passed to methods by reference ehile
> > primitives are passed by value.
>
> Oh brother, here we go again...
> No, EVERYTHING is passed by value. The object
> reference is passed in by value as well. If the
> object is mutable, you can call methods on it to
> change its state. However, that won't work for
> Double, as Double is immutable anyways.
Isn't the first point a little pedantic? The second point has merit though.
> "ehile" should read "while"
>
> I understand conceptually that you pass an object
> handle and not the object itself. Perhaps if I ever
> start thinking in Java then the distinction will be
> apparent.
Or perhaps, grasshopper, when the distinction becomes apparent, you will be ready to take the first step down the path toward thinking in Java.
But seriously. Passing a reference by value is conceptually similar to passing an object by reference. However, given that Java's types include references but not objects, it makes more sense and fits better with the definition to say references are passed by value. That is in fact what happens--the refrence has a value (the "address," in a sense, of an object) and that value is duplicated and passed.