Learn Java Programming - Overriding the .hashCode() method Tutorial

Publicado el: 14 enero 2016
en el canal de: Daniel Ross
2,240
27

The Object class contains eleven methods; over half of those methods are somehow dependent upon other methods within the Object class to function properly. In a previous tutorial I discussed the relationship between the .wait() method and the .notify() and .notifyAll() methods. One of the most widely used methods, .equals(), shares a special relationship with the .hashcode() method. At this point you should already be familiar with invoking the .equals() method on an object. The purpose of this tutorial is to explain what a hash code is and how to properly override the .hashCode() method.

So what is a hash code? A hash code is a number, and in Java it can simply be any number that fits into the primitive int range of -2147483648 to 2147483647.
What purpose does a hash code serve? The purpose of a hash code is to provide a quick way of locating an object when it is mixed in with a bunch of other objects (clear as mud right???).
Without realizing it, we use hash codes all over the place in everyday life. Imagine that you have a craving for a can of Coca-Cola (Coke) so you head over the grocery store to get one. When you step into the grocery store you are presented with a bunch of stuff for sale. That "stuff" is comprised of thousands of objects; a six-pack of Coke is an object and it the specific object that you are searching for amongst a sea of other objects.
So where to we begin? We'll just start walking around hoping to stumble across it and we will locate it eventually after some time has elapsed.


En esta página del sitio puede ver el video en línea Learn Java Programming - Overriding the .hashCode() method Tutorial de Duración hora minuto segunda en buena calidad , que subió el usuario Daniel Ross 14 enero 2016, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 2,240 veces y le gustó 27 a los espectadores. Disfruta viendo!