On Mon, Aug 3, 2009 at 6:22 PM, Todd Volkert<[email protected]> wrote:
> We use reference equality comparison
> because we don't want to incur the string comparison overhead, but we do
> need to perform some comparison.
You do realize the instance comparison difference?
String abc = "Abc";
String def = "A" + "b" + "c";
String rst = create( "A" ) + create( "b" ) + create( "c" );
String xyz = new StringBuffer().append( 'A' ).append( 'b' ).append(
'c' ).toString();
boolean r1 = abc == def;
boolean r2 = abc == rst;
boolean r3 = abc == xyz;
private String create( String in )
{
return new String( in );
}
Can you tell me which one of those r1-r4 that are true?? (I can't, and
I suspect it is compiler/jre dependent, but I think the spec requires
only abc==def to be true, and the others are (jit-)compiler smartness
only).
I hope you don't pull too many stunts/assumptions and do "programming
by coincidence"(tm) ;-).
Cheers
--
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java
I live here; http://tinyurl.com/2qq9er
I work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug