Can we avoid string interning in java?

Can we completely disable string interning. This may not be very useful, but just a thought. I can think of at least one point where this might be useful, for example, during jvm setup, controlling the size of perm gen.

For example, if I give the OSGI infrastructure, and everyone can add any number of their own packages, and each set of lines inside the line can completely ruin my settings. (Of course, I know that we need to tune in to a specific fixed distribution, but still ...)

Any thoughts!

+2
source share
4 answers

/ JVM. , .

( , "" ).

+6

, . char [] . .

String hi = new String(new char[] { 'h', 'i' }); // not interned.

, .

OSGI, ,

, , , , NewSize, GC. - OSGi.

, , .

+1

String is final class and can not be extended. Therefore, no - you cannot remove the ability to put lines in Java.

0
source

Source: https://habr.com/ru/post/1649131/


All Articles