| Author |
Equlas method and Collections
|
Varalakshmi Ramanarayan
Ranch Hand
Joined: Oct 28, 2007
Posts: 108
|
|
Hi all, I came accross this piece of code on "Sahir's TestCafe MockTest". I was very sure that equal methods would return false(because Vectors and ArrayList are two different classes and their instances cannot be equal). But It returned true. Can someone expalin the reason for this behaviour. Thanks in advance.
|
SCJP 5 - 87%<br />Next SCWCD
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Varalakshmi Ramanarayan: ... Can someone expalin the reason for this behaviour...
Yes, the API documentation can explain this behavior. (Note that ArrayList inherits its implementation of equals from AbstractList.) If that doesn't clear it up, please post back. [ February 02, 2008: Message edited by: marc weber ]
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Varalakshmi Ramanarayan
Ranch Hand
Joined: Oct 28, 2007
Posts: 108
|
|
Hi Marc, Thanks for your quick reply. I got my answer too.
This line helped me a lot. Before posting, I just looked at Vector and ArrayList in the API. Thanks..
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Varalakshmi Ramanarayan: ... Before posting, I just looked at Vector and ArrayList in the API...
Glad you got it! In this example, you're calling equals on an ArrayList reference (a.equals(v)), so you would check the API for ArrayList. In the documentation for ArrayList, you won't see the equals method listed in the "Method Summary" section, but directly underneath that, you will see the equals method listed in the "Methods inherited from class java.util.AbstractList" section. Clicking on that link gives you the description.
|
 |
 |
|
|
subject: Equlas method and Collections
|
|
|