Created
August 1, 2018 10:49
-
-
Save jskeet/0ae888dafecbe695e3e638e15c6154bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class Test { | |
public static void main(String... args) { | |
String x = "abc"; | |
String y = "def"; | |
String xy = x + y; | |
xy.intern(); | |
// With this line here, the output is true | |
// which shows that the literal here is only taken | |
// from the string pool at the point of execution. | |
// If this line is moved to before the xy.intern() | |
// call, the result is false | |
String abcdef = "abcdef"; | |
System.out.println(abcdef == xy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment