GenericData is the base class for 'requst' and 'response' objects in Google Java API bindings. It inherits equals from AbstractHashMap, which is a mistake. Let's consider this expression (Directory API):
directory.users().list().equals(directory.groups().list())
Intuition says it should be false, but in fact is true, because in this example it happens that both left and right side has exactly the same keys and values in the AbstractHashMap, which makes strange errors for example when somebody tries to put objects to own HashMaps (eg to make some simple caching).
The reason of this problem is that AbstractHashMap.equals and AbstractHashMap.hashCode dosn't take this.getClass() into account (just like all implementations of Map do), but GenericData isn't just a Map, it's just a regular object with generic access mechanism, and IMHO should have valid equals and hashCode implemented.
The same is as for toString: strings like {...} don't tell me of which class this object is, eg is this directory.users().list() request or directory.groups().list() request?
GenericDatais the base class for 'requst' and 'response' objects in Google Java API bindings. It inheritsequalsfromAbstractHashMap, which is a mistake. Let's consider this expression (Directory API):Intuition says it should be
false, but in fact istrue, because in this example it happens that both left and right side has exactly the same keys and values in theAbstractHashMap, which makes strange errors for example when somebody tries to put objects to ownHashMaps(eg to make some simple caching).The reason of this problem is that
AbstractHashMap.equalsandAbstractHashMap.hashCodedosn't takethis.getClass()into account (just like all implementations ofMapdo), butGenericDataisn't just aMap, it's just a regular object with generic access mechanism, and IMHO should have validequalsandhashCodeimplemented.The same is as for
toString: strings like{...}don't tell me of which class this object is, eg is thisdirectory.users().list()request ordirectory.groups().list()request?