Thursday 15 April 2010

java - Why is SparseIntArray.equals(Object) not working? -



java - Why is SparseIntArray.equals(Object) not working? -

i using sparseintarray , puzzled behavior:

public static sparseintarray getarray() { sparseintarray result = new sparseintarray(); result.append(0, 99); result.append(1, 988); result.append(2, 636); homecoming result; } public static void testarray() { sparseintarray first = getarray(); sparseintarray sec = getarray(); if( first.equals(second) ) { log.v(tag,"first "+first.tostring()+" == sec "+second.tostring()); } else { log.v(tag,"first "+first.tostring()+" != sec "+second.tostring()); } }

output:

11-06 14:53:15.011: v/filename(6709): first {0=99, 1=988, 2=636} != sec {0=99, 1=988, 2=636}

i know using == between 2 objects compare object addresses, in case different, here using sparseintarray.equals(object other) , intended result not unexpected.

i sure can roll own compare method, sounds kind of silly. point of having base of operations class object.equals(object other) method if cant rely on it?

can point mistake?

i searched code of sparseintarray. if referring android.util.sparseintarray, doesn't override equals, means uses default implementation of object class, compares references.

what point having base of operations class object.equals(object other) method if cant rely on it?

actually, can't rely of base of operations class object.equals, since exactly don't want do:

public boolean equals(object obj) { homecoming (this == obj); }

it's writers of class decide whether override equals , give different implementation.

java android equals sparse-array

No comments:

Post a Comment