Created
May 4, 2013 19:42
-
-
Save TomTasche/5518509 to your computer and use it in GitHub Desktop.
i had a discussion about the possible existence of a global "String pool" in newer versions of Java. turns out, there is no such thing. however, hardcoded strings are "pooled", i.e. String a and String b in the example are the *same instance of String*.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String a = "test"; | |
String b = "test"; | |
System.out.println("a == b? " + (a == b)); // true | |
String c = "tester"; | |
String d = a + "er"; | |
System.out.println("c == d? " + (c == d)); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
turns out, there IS a string pool after all. as i understand it, my test fails to prove its existence by design of the java developers.