Whether it works depends on the hashCode function. A hashCode implementation is required to map equal objects to the same value. It is desirable, as far as possible, to map unequal objects to different values, but that is not required and is often impossible. Many classes have more possible unequal object values than there are int values.
If your hashCode function does map any pair of objects that are not equal to two different hashCode values then two objects of the class are equal if, and only if, they have the same hashCode and it could be used in equals.
Do not count on other classes having distinct hashCode values for unequal objects. For example, there are more distinct String values than int values, so String's hashCode has to map unequal objects to the same hashCode.
intvalues that don't necessarily mean that the objects are equal.