Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!g2g2000vbl.googlegroups.com!not-for-mail From: Alex J Newsgroups: comp.lang.java.programmer Subject: The behavior of "equals" method of Arrays.asList() implementation Date: Tue, 28 Jun 2011 02:19:02 -0700 (PDT) Organization: http://groups.google.com Lines: 24 Message-ID: NNTP-Posting-Host: 94.25.210.15 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1309252743 18516 127.0.0.1 (28 Jun 2011 09:19:03 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 28 Jun 2011 09:19:03 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g2g2000vbl.googlegroups.com; posting-host=94.25.210.15; posting-account=WEhrTAoAAACB_dCNiMk-LATj1SOnQi04 User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HNKRUAELSC X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.91 Chrome/12.0.742.91 Safari/534.30,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5723 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!