I have a Long
and a String
. I want to create a hash of both of those object. Meaning, I want some function that will take arbitrary number of objects and return me one hash value. Does such a function exits?
Something like this:
public int getHash(Object... objects)
{
//somehow returns a hash of all these objects
}
Take a look at Arrays.hashCode(Object[])
.
It doesn't accept varargs, but you can wrap it with your own varargs library function if you wish:
public static int computeHashCode(Object... objects) {
return Arrays.hashCode(objects);
}
The Apache Commons HashCodeBuilder has a reflection-based invocation that is similar to what you want.
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.