Hello,
Many of the subclasses of ucar.units.Unit override equals(Object), but
fail to override hashCode(). As a result, the hashCode() implementation
that is inherited from Object no longer satisfies its contract, namely:
If two objects are equal according to the equals(Object) method, then
calling
the hashCode method on each of the two objects must produce the same
integer result.
Here is an example of the contract being broken:
Unit unit1 = UnitFormatManager.instance().parse("m/s");
Unit unit2 = UnitFormatManager.instance().parse("m/s");
System.out.println(unit1.equals(unit2)); // Prints "true"
System.out.println(unit1.hashCode() == unit2.hashCode()); // Prints "false"
As a result of this behavior, Units are not generally usable in a
hashing container.