This is a compiler that does string interning. Therefore, during compilation, identical lines are optimized. Therefore, I think the answer you want is no. The virtual machine does not do this, it is a compiler. You can call String.intern()to get a common string object in the string pool:
String str1 = "string";
String str2 = new String("string");
String str3 = str2.intern();
str1 == str2
str2 == str3
str1 == str3
Lines created at runtime are not executed automatically.
source
share