This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

equals Method  RSS feed

 
sivanagaswathi kallam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the role of instanceof operator in equals method?
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sivanagaswathi kallam wrote:What is the role of instanceof operator in equals method?

It checks that the object being compared is the same type as this.

Remember, the signature for an equals method is:
  public boolean equals(Object o) { ...

Winston
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, it performs a null-check.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!