Tuesday, August 14, 2012

Generics - Part 1


Before diving into Generics we have to get a better understanding of some Object's methods like hashCode() and equals().

Overriding equals()

The main purpose of this method is compare if the objects are meaningfully equivalent, if you don't override this method you cannot use the object as a key in a hashtable, it's because when you don't override a equals() method it uses the operator == to do a comparison.

Let's override a equals() method.

Overriding hashCode()

Hascode is used by some Collections, it provides a way to store the objects in a collection as well as it helps to locale the objets within the collections.  If two objects are equal, their hashcodes must be equal as well.

Implementing hashCode()
Let's review equals and hashCode methods



After this brief introduction needed to work with Collections you're able to dive into Collections which will be covered in the next section.

No comments: