This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object equals

 
Kasun Wixkramanayake
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

CaseInsensitiveString cis = new CaseInsensitiveString("Polish");
String s = "polish";

cis.equals(s)//true
s.equals(cis)//flase

why it happens like that
 
Campbell Ritchie
Sheriff
Pie
Posts: 50276
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to have posted in the wrong location; let’s move your discussion somewhere more appropriate.

Is that a quote from Joshua Bloch’s book? Doesn’t he explain it? Which bit do you not understand?
 
Kasun Wixkramanayake
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldnt understand what is meant by symmetry and One-way interoperability
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kasun Wixkramanayake wrote:I couldnt understand what is meant by symmetry and One-way interoperability


Symmetry means that if X and Y are both non-null, then X.equals(Y) must return the same results as Y.equals(X). The CaseInsensitiveString class violates that.

It looks like "one-way interoperability" basically refers to the specific manner in which it is violating symmetry. By using that instanceof test, CaseInsensitiveString.equals(String) can be true, but String.equals(CaseInsensitiveString) can never be true.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50276
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesterday, I wrote: . . . Is that a quote from Joshua Bloch’s book? . . .
It is on page 35 in the 2nd edition of Effective Java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic