Best implementation for hashCode method for a collection

后端 未结 20 3085
难免孤独
难免孤独 2020-11-22 01:39

How do we decide on the best implementation of hashCode() method for a collection (assuming that equals method has been overridden correctly) ?

20条回答
  •  悲哀的现实
    2020-11-22 02:39

    I use a tiny wrapper around Arrays.deepHashCode(...) because it handles arrays supplied as parameters correctly

    public static int hash(final Object... objects) {
        return Arrays.deepHashCode(objects);
    }
    

提交回复
热议问题