Refer to the following code:
\\many codes here
StringBuffer s1 = new StringBuffer( "String" );
StringBuffer s2 = new StringBuffer( "String" );
if ( s1.equals( s2 ) )
{
System.out.println( "TRUE" );
}
else
{
System.out.println( "FALSE" );
}
//many codes here.
This code compiled no error with output is "FALSE".
I know equals() is the method which declared in class
String, why can we called by class StingBuffer directly here?
Besides, why can we get the result "TRUE" if we change variable type of s1 from StringBuffer to String instead of "FALSE" with the type is StringBuffer? Thanks.