Thibault Kruse
2014-12-10 09:46:58 UTC
Hi,
in another thread I mentioned this symptom in Groovy, so this is a bump:
class UnorderedList<E> extends ArrayList<E> implements Set<E> {
UnorderedList( Collection items ) {
this.addAll(items)
}
public static void main(String[] args) {
UnorderedList x = new UnorderedList([1,2,3])
UnorderedList y = new UnorderedList([3,1,2])
assert x.equals( y ) // true via DefaultGroovyMethods equals(Set, Set)
assert x == y // false via DefaultGroovyMethods equals(List, List)
}
}
Is this a Bug or feature?
I also note that this code fails Static type checking because
allegedly x.equals(y) is an ambiguous Method call to Groovy, I also
guess because of DefaultGroovyMethods. Not sure what proper dynamic
behavior should be here, but equals() taking a different route than ==
seems not the ideal solution.
I am aware that it does not make much sense to implement both Set and
List, since their semantics are different. Yet the way Groovy behaves
when dynamically typed seems odd, hinting at a possible bug somewhere.
cheers,
Thibault
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
in another thread I mentioned this symptom in Groovy, so this is a bump:
class UnorderedList<E> extends ArrayList<E> implements Set<E> {
UnorderedList( Collection items ) {
this.addAll(items)
}
public static void main(String[] args) {
UnorderedList x = new UnorderedList([1,2,3])
UnorderedList y = new UnorderedList([3,1,2])
assert x.equals( y ) // true via DefaultGroovyMethods equals(Set, Set)
assert x == y // false via DefaultGroovyMethods equals(List, List)
}
}
Is this a Bug or feature?
I also note that this code fails Static type checking because
allegedly x.equals(y) is an ambiguous Method call to Groovy, I also
guess because of DefaultGroovyMethods. Not sure what proper dynamic
behavior should be here, but equals() taking a different route than ==
seems not the ideal solution.
I am aware that it does not make much sense to implement both Set and
List, since their semantics are different. Yet the way Groovy behaves
when dynamically typed seems odd, hinting at a possible bug somewhere.
cheers,
Thibault
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email