/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
String sl
= "First Name" ; // a string literal
System .
out .
println ( "s1 = " + sl
+ " hashCode = " + mimicObjectToString
( sl
) ) ; sl += "Kumar" ; // appended ,
System .
out .
println ( "s1 = " + sl
+ " hashCode = " + mimicObjectToString
( sl
) + "\n " ) ; // if the output differs it means a new reference has been created during appending
System .
out .
println ( "so = " + so
+ " hashCode = " + mimicObjectToString
( so
) ) ; so += "Kumar" ;
System .
out .
println ( "so = " + so
+ " hashCode = " + mimicObjectToString
( so
) + "\n " ) ;
System .
out .
println ( "sb = " + sb
+ " hashCode = " + mimicObjectToString
( sb
) ) ; sb.append ( "Kumar" ) ;
System .
out .
println ( "sb = " + sb
+ " hashCode = " + mimicObjectToString
( sb
) + "\n " ) ;
System .
out .
println ( "Changed hashCode denotes different reference has been created, implying its \" immutable\" nature" ) ; }
//prevent a NullPointerException by returning null if o is null
if ( o != null ) {
result
= o.
getClass ( ) .
getName ( ) + "@" + Integer .
toHexString ( System .
identityHashCode ( o
) ) ; }
return result;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJICBTdHJpbmcgc2wgPSAiRmlyc3QgTmFtZSI7ICAvLyBhIHN0cmluZyBsaXRlcmFsCgkgIFN0cmluZyBzbyA9IG5ldyBTd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