Showing posts with label equal. Show all posts
Showing posts with label equal. Show all posts

Important point should remember about Object's hashCode and Equal method to Freahser Java developer at time of interview

  • The default implementation of hashCode() provided by Object is derived by mapping the memory address of the object to an integer value. 
     
    equals() and hashCode(). In general, if you override one of these methods, you must override both, as there are important relationships between them that must be maintained
    
    Java object support hashCode() allows for efficient storage and retrieval using hash-based collections.
    
    
    the equals() method must exhibit the following properties: 
    Symmetry: For two references, a and b, a.equals(b) if and only if b.equals(a) 
    Reflexivity: For all non-null references, a.equals(a)
    Transitivity: If a.equals(b) and b.equals(c), then a.equals(c)
    Consistency with hashCode(): Two equal objects must have the same hashCode() value