See a very interesting situation today, if you want to use the ToString method to return the address of the object, you might consider using the This keyword, but this time there will be a problem, the compiler sees a string object followed by a "+" and is not a string object, The compiler attempted to convert this to a string object, and by invoking the ToString method of this, a recursive call occurred. If you really want to print out the memory address of the object, you should call the Object.ToString () method, so you should not call the Super.tostring () method with this.
ImportJava.util.*; Public classteststring {/** * @paramargs*/ PublicString toString () {return"Addresss is:" +Super. toString () + "\ n"; } Public Static voidMain (string[] args) {//TODO auto-generated Method Stublist<teststring> s =NewArraylist<teststring>(); for(inti = 0; I < 3; i++) {S.add (Newteststring ()); } System.out.println (s); }}
-----------------------------
When the string content is changed, the method of the string class returns a new string object, and if the content does not change, the method of string simply returns a reference to the original object.
The string1 of Java programming idea