About Question enthuware.ocajp.i.v7.2.999 :
Posted: Sat Mar 02, 2013 9:38 am
I would like to add a clarification.
basically intern of course is useful only for String object as the String literals are automatically interned.
A part from that, the use of intern to be meaningful must be done at the same time the object it's created.
example:
If it had been done something like str.intern(); after the creation of str it of course would be too late as the different object would have been already created.
Let's pass this OCA exam.
basically intern of course is useful only for String object as the String literals are automatically interned.
A part from that, the use of intern to be meaningful must be done at the same time the object it's created.
example:
Code: Select all
String str1 = "Indeed";
String str = new String("Indeed").intern();
System.out.println(str1==str);
Let's pass this OCA exam.