So I've read that if you write this:
String a="foo";
String b="foo";
System.out.println(a==b);
it will print "true", because the first implementation checks the memory pool looking for "foo", it cant find it so it creates a new object and puts foo in the memory pool, then every other string will be pointing to the same object.
and if you write:
String a="foo";
String b=new String("foo");
System.out.println(a==b);
it will print "false", because you force a creation of a new object for b so it wont take it from the pool.
my question is if you write this:
String a=new String("foo");
String b="foo";
System.out.println(a==b);
why does it still print "false" ? I mean "a" creates a new object and doesn't look in the memory pool, but b should look in the memory pool and find the object "a" created and point to it. what am I missing here? thank you.