Vector <Double> x = new Vector<Double>();
Vector <Integer> y = new Vector <Integer>();
System.out.print(x.equals(y));
This prints:
true
Why? Isn’t equals() -by default- supposed to compare if two references point to the same object?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
equalsis implemented inAbstractList. It goes through elements in the list and returns false if any are not equal. Because your lists have no elements, true is returned.As Tom mentioned in the comments, reading the contract of the
ListInterface you will see that it defines the behavior.