Quantcast
Channel: Scratch Where It's Itching
Viewing all articles
Browse latest Browse all 73

Interning String Literals

$
0
0
I found this kind of code in our application:
  public static final String CONSTANT_STRING = "Some value".intern();

Interning a String means storing it into a common pool of Strings managed by the JVM, so that if I already used this String somewhere, I will only get back its reference. It may be a good idea sometimes, but you have to know that all String literals are already interned by the JVM. As useless as calling toString() on a String.


Viewing all articles
Browse latest Browse all 73

Trending Articles