I have two questions and unfortunately I can't find answers.
If we declare 1000 boolean variables equals to
true
will all of them have the same reference totrue
literal?Java is pass-by-value so consider the code
public class Test { public static boolean global; public static void main(String[] args) { foo(false); System.out.println(global); } public static void foo(boolean bar) { global = bar; } }
In foo()
method the primitive value of boolean variable will be copied and it means that global
will have another reference for the literal. Or will Java perform some kind of pool lookup for this and global
will also reference the same memory location as argument?