I have a scenario where I want to set a Boolean object and then use its booleanValue() in the constructor later in the method. However, the area in which the object is installed is different. It is set in the method called by the method in which the object is first created. Based on my understanding of how Java passes primitive and object arguments and reads several messages on the Internet (like this ), when an object is passed to a method, its properties are passed by reference and any change to the called method should be reflected in the calling method after how the called method completed execution. However, I notice that when the called method is completed, any change in it does not work in the calling method.
Here is a snapshot of my script:
private CustomObject1 callingMethod(){ Boolean b = Boolean.TRUE; List<CustomObject2> list = this.calledMethod(b);
By the time the CustomObject code is CustomObject creation of b.booleanValue() always true, even if the if-statement in callingMethod() is true and Boolean in this method is set to false.
I donβt want to change the return type of the calling method as Boolean , because this will require changes in other bits of the code that can cause this method. Currently, they only need to change the signature, but changing the type of return will require additional work, since the logic must be supported (for example, filling out a list and then doing something with it).
source share