wood burning stoves 2.0*
The moose likes Features new in Java 7 and the fly likes equals and hashCode of Java7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "equals and hashCode of Java7" Watch "equals and hashCode of Java7" New topic
Author

equals and hashCode of Java7

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I have used Google Guava for overriding hashCode/equals-Method via com.google.common.base.Objects Methods.

Java 7 provides the Objects.hash and Objects.equals-Method.

Are guava (hashCode, equals) and java objects (hash, equals) the same?

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

They definitely serve the same purpose. These methods have been in demand for years; not only Google, but also Apache Commons Lang has them. Oracle (or actually Sun) should have added them long before.
You need to check the source code of both to see whether or not they are implemented the same. Oracle's code can be found in the src.zip file inside the JDK folder.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
Okay, thank you, you are right. It is the same !
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You're welcome, and thanks for verifying
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: equals and hashCode of Java7