×

Loading...

No democracy among Java objects?

Hi, jabber, thanks a lot for your answer.
I totally agree with you, but look at the following cases:

1) String s1=new String("abc");
String s2=new String(edf");
s1==s2;
This is a standard Java statement.
Of course, compile and run well.

2) "abc"=="edf";
Complie and run well.
A little bit strange since we compare two objects(not references), nevertheless it is understandable if noticing special properties of anonymous strings.

3) new String("abc")==new String("edf");
doesn't compile.
Excluded Java standards. However,

4) For all wrapper classes like
new Boolean("TRUE")==new Boolean("hi");
compile and run well!

So democracy doesn't exist, there are some special objects having extraordinary rights.
Do you agree?
Report

Replies, comments and Discussions: