java - Conflict in toString default and Overriden toString -
If I override with the actual implementation of the string, then it gives different results compared to the string implementation than the default. Please Help me understand why there are different results.
@ Override public string toString () {return get get callclass (). GetName () + "@" + Integer.toHexString (hashCode ()); }
Output for:
leo.test.Teste@addbf1
< P> Output for default: leo.test.Teste@19821f
Full code:
public class test {public static zero main (string array []) {test T = new test (); Println (t); } @override public string toasting () {getClass (). GetName () + "@" + integer. Hoststress (hashkotted ()); }}
I think your problem is the default implementation of hashCode ( )
, this Therefore, if you do two tests (one with an override method, without one), you can get different results.
If you try it in this way:
public class teststorage {public static zero major (string [] algs) {teststorming TTS = new teststoest (); Println (TTS); Println (tts.superToString ()); } Public string superstorming () {return super. Tosting (); } @override public string toasting () {getClass (). GetName () + "@" + integer. Hoststress (hashkotted ()); }}
There will be one result for your two methods:
com.test.TestToString@8dc8569 com.test.TestToString@8dc8569
Comments
Post a Comment