This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi all! The following: Byte b1 = new Byte("127"); if(b1.toString() == b1.toString()) System.out.println("True"); else System.out.println("False"); results to "False". I thought the toString method would twice return a reference to the String "127" from the JVM Stringcontainer...and so this would result to "True". So what happens there? Are there returned two new String instances created with ... what? Thanks...! Ciao Stefano
because toString of class Byte invokes toString of class Integer and the latter create the String using the keyword "new" which means that every time toString is invoked a new String instance is created. The content may be the same but the references are different and == compares the references not the content. HIH [ February 12, 2002: Message edited by: Valentin Crettaz ]