Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generics

 
swaraj gupta
Ranch Hand
Posts: 182
C++ Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if I use it as:
Why exactly one element is getting added to the TreeSet if both the objects d1 and d2 are different....
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
return 0; implies equality

When 2 objects are equal, the duplicate one will not make it into the set
 
swaraj gupta
Ranch Hand
Posts: 182
C++ Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:return 0; implies equality

When 2 objects are equal, the duplicate one will not make it into the set

doesn't TreeSet uses equals() to test equality of two objects...?

where I can read about this?
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
swaraj gupta wrote:doesn't TreeSet uses equals() to test equality of two objects...?

where I can read about this?


No. And the JavaDoc for TreeSet states this in one of the first few paragraphs. The JavaDoc further states that the comparator/comparable must also be "consistent with equals", meaning it will assume that the comparable/comparator methods can be used instead of equals -- no further checking is done.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic