-3
public class Memory {

    public static void main(String[] args) { // Line 1
        int i=1; // Line 2
        Object obj = new Object(); // Line 3
        Memory mem = new Memory(); // Line 4
        mem.foo(obj); // Line 5
    } // Line 9

    private void foo(Object param) { // Line 6
        String str = param.toString(); //// Line 7
        System.out.println(str);
    } // Line 8

}

such as line 7 here. why line 7 str is in the constant pool

Reporter
  • 3,776
  • 5
  • 31
  • 46
  • 1
    How did you verify it was interned? Did you check if `str == str.intern()`? `Object#toString` builds a string from concatenation of non-literal values, I'd be surprised if this was the case in your test. – Rogue May 27 '22 at 13:24

0 Answers0