java - Intered object with one reference? Does scope apply to interened objects? -
is string object holding value "dog" still considered interned if 0 variable referencing it?
string 0 = "dog";
how many objects in code? either there's 1 because interned objects ignore scope, or there's 2 because scope still applies.
string jack = "skellington"; for(//stuff) { string sally = "skellington"; }
string literals interned i.e pool created them. if after decalring 1 string literal, referenced anywhere instance of jvm, picked pool only
1)one object created. not matter if referenced down line or not
2)one object created
see intern method @ http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/string.html
Comments
Post a Comment