It's not the first year I use Java for development, but I faced this issue the very first time. I have pretty complex permission module in my system which modifies object I return to the client in accordance with access control list.
To be short, I need to nullify object passed to another function. Here is some code:
public static void main(String[] args) {
String s = "filled";
nullify(s);
System.out.println(s);
s = null;
System.out.println(s);
}
public static void nullify(String target) {
target = null;
}
I understand that s
is passed to nullify()
by value and when I setting target
to null it doesn't affect s
. My question is there any way in Java which allows me to set s
to null
having target
?
Thanks.
p.s. I found lots of information about setting variables to null
but all of them was related to garbage collection and didn't answer my question.