This is the mail archive of the
java-patches@sourceware.cygnus.com
mailing list for the Java project.
Re: [patch] java.io.File fixes and String.substring() optimization
Tom Tromey wrote:
> >>>>> "Bryce" == Bryce McKinlay <bryce@albatross.co.nz> writes:
>
> Bryce> The former fix also prompted me to check if String.substring()
> Bryce> would do the right thing if it was called with (0, length) - it
> Bryce> should probably return itself in this situation (the spec says
> Bryce> somewhere that strings with equivalent content can and should
> Bryce> be the same object, right?), so I patched that too.
>
> Do you have a reference for this?
public class Substr
{
public static void main(String args[])
{
String a = "asdfg";
String b = a.substring(0, 5);
if (a == b) System.out.println("same");
}
}
[bryce@reason tests]$ java Substr
same
[bryce@reason tests]$
Remember, the "==" operator tests for object equality, NOT string
equality.
regards
[ bryce ]