0

I understand the interning and StringPool concepts. But I fail to understand how a String literal is converted to String object. For e.g.

String abc = "abc";

The above line will create an String object. How does this shortcut work (in java)?

  • 1
    That line *might* create a `String` object. If `"abc"` is already in the string pool, it'll just point `abc` at the existing object. – azurefrog Jul 05 '16 at 19:16
  • Not sure what you mean by how..a String literal is a String object by definition. See [the Java Spec](https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.5) – copeg Jul 05 '16 at 19:21
  • Another duplicate: http://stackoverflow.com/q/3052442/10077 – Fred Larson Jul 05 '16 at 19:23
  • imho this question seems primarily about the prescribed operation of the JVM, not the JLS definition of a string literal--I suggest we reopen it – obataku Jul 05 '16 at 19:31
  • This is just built into the Java language; it's not something that works for anything other than strings. It's just how Java works. – Louis Wasserman Jul 05 '16 at 20:58
  • this is not a duplicate question, this question is more about how JVM works – purnendu SAHA Jul 26 '16 at 05:33

0 Answers0