Java - 未合并的字符串

Java - Unpooled String

Is there a legal way to force JVM not to store particular String instance in a long-lived string pool?

除了不用字符串字面量初始化外,恐怕没有。

Does new String() provide this feature and I can be 100% sure that value created this way will be put into the heap and not into the pool unless I call intern()?

是(请记住,如果您编写 String str1 = new String("Hello");,则 str1 引用的 String 实例将不会被内部化,而 String 实例将被创建对于文字字符串 "Hello" will)。

另请注意,池在堆中的确切存储位置取决于 JVM 的版本,如所述