Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #5723
| From | Alex J <vstrength@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | The behavior of "equals" method of Arrays.asList() implementation |
| Date | 2011-06-28 02:19 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <b30a98ec-acc8-4e7b-bb9d-0de48a554d07@g2g2000vbl.googlegroups.com> (permalink) |
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!
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar
The behavior of "equals" method of Arrays.asList() implementation Alex J <vstrength@gmail.com> - 2011-06-28 02:19 -0700
Re: The behavior of "equals" method of Arrays.asList() implementation Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-28 07:08 -0400
Re: The behavior of "equals" method of Arrays.asList() implementation Lew <noone@lewscanon.com> - 2011-06-28 07:29 -0400
Re: The behavior of "equals" method of Arrays.asList() implementation Roedy Green <see_website@mindprod.com.invalid> - 2011-06-28 10:04 -0700
csiph-web