Accueil
 Sommaire du cours
 1  Introduction à Java
 2  Concepts de bases de Java
 3  Classes et objets en Java
 4  Généralisation spécialisation en Java
 5  Organisation des sources Java
 6  API Java
 7  Exceptions en Java
 8  Concepts objets avancés en Java
 8.1  Copie simple/légère
 8.2  Retour sur \texttt hashCode()
 8.2.1  Exemple hashCode
 8.3  Retour sur les exceptions
 Bibliographie

 Contacts

W3C validator

Département INF  
 Conception et programmation orientées objet


8.2.1 Exemple hashCode
 
package studsequals; 
public class Personne { 
    private String nom, prenom; 
4    public Personne(final String nom, final String prenom){ 
        this.nom = nom; this.prenom = prenom; 
    } 
    @Override 
8    public boolean equals(Object obj) { 
        if (this == obj) return true; 
        if (obj == null) return false; 
        if (!(obj instanceof Personne))return false; 
12        Personne other = (Personne) obj; 
        if (nom == null) { 
            if (other.nom != null) return false; 
        } else if (!nom.equals(other.nom)) return false; 
16        if (prenom == null) { 
            if (other.prenom != null)  return false; 
        } else if (!prenom.equals(other.prenom)) return false; 
        return true; 
20    } 
}

    précédent     suivant 


Christian Bac, Denis Conan, Télécom SudParis, CSC 4002, Octobre 2015