According to the documentation the == operator calls the equals method. This doesn't seem to be the case with maps in groovy. Is this a bug or am I doing something wrong?
When a class extends LinkedHashMap and overrides equals
class CustomExtend extends LinkedHashMap<String, String> {
@Override
boolean equals(Object o) {
false
}
}
def customExtend = new CustomExtend()
customExtend.put('key', 'value')
assert [key:'value'] == customExtend
assert customExtend == [key:'value']//should be false
Another strategy I tried is delegation
class CustomDelegate {
@Delegate
LinkedHashMap map = [:]
@Override
boolean equals(Object o) {
false
}
}
def customDelegate = new CustomDelegate()
customDelegate.put('key', 'value')
assert [key:'value'] == customDelegate
assert customDelegate == [key:'value']//should be false