This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
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 ]