Java parameters are passed by value
Thats wrong!!
In Java all parameters are passed by reference, even Strings and booleans!
But if you assign a primitieve type within a method to some value like
or
then the reference to the object b is changed to a new object. And then you have to know:
Changing references of an object within an method will be lost as soon as the method has finished. This is so because every method just builds an temporary stack for its calculation during the interpretation of the .class file.
There is only one way to maintain changes of refenrences wihtin a method:
you have to return the new reference and catch it to your old reference:
of yourse you can wrap it into an object and change its members with settsers but thats not changing the reference of the object but changing its members.