A
Alex J
Basically I wonder if it is safe to use equals for collections (and
junit's assertEquals in particular which in fact results in the
*.equals invocation).
One of collection instances I am working with is returned from
Arrays.asList(..) method invocation.
Sun JDK sources defines no equals method for
java.util.Arrays.ArrayList inner class so I guess it is not safe to
compare collections in that way.
Surprisingly, equals called from Arrays.ArrayList "magically" (I can't
find another word) checks the elements in the collection!
I tried to walk throug the sources by using "step into" in the
debugger, but it mysteriously transfer control to the equals method of
my class (and yes, I have JDK sources attached, e.g. I can walk
through implementation of certain String method).
So the first question is: whether it is safe to use equals for *all*
the JDK's collections?
The second question is whether JVM adds "hidden" implementation in
certain places and Arrays helper List implementation is one of those,
so I may expect Arrays.asList(...) implementation behave in the same
way on different JDKs?
Thanks in advance!
junit's assertEquals in particular which in fact results in the
*.equals invocation).
One of collection instances I am working with is returned from
Arrays.asList(..) method invocation.
Sun JDK sources defines no equals method for
java.util.Arrays.ArrayList inner class so I guess it is not safe to
compare collections in that way.
Surprisingly, equals called from Arrays.ArrayList "magically" (I can't
find another word) checks the elements in the collection!
I tried to walk throug the sources by using "step into" in the
debugger, but it mysteriously transfer control to the equals method of
my class (and yes, I have JDK sources attached, e.g. I can walk
through implementation of certain String method).
So the first question is: whether it is safe to use equals for *all*
the JDK's collections?
The second question is whether JVM adds "hidden" implementation in
certain places and Arrays helper List implementation is one of those,
so I may expect Arrays.asList(...) implementation behave in the same
way on different JDKs?
Thanks in advance!