import java.util.Objects; class MyClass { int x; float y; String z; @Override public int hashCode() { return Objects.hash(x, y, z); } }As you can see it takes any kind of variable. It calls hashCode() on all then hashes the result. Records in Java 14+ avoid this altogether.
Programming Tips - Java 1.7 or later: easy way to implement hashCode()
Date: 2020apr14
Language: Java
Q. Java 1.7 or later: easy way to implement hashCode()
A. Use the Objects.hash() utility function which was introduced in Java 1.7
(Android level 19 if you are developing for that platform)
Example: