salut

j'ai redéfinie equals pour un objets

longVal étant de type long
stringVal étant de type String

j'obtient une java.lang.nullPointerException à l'endroit spécifié

il y a une comparaison de 1 et 21 et ça crash

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
 
        if (o instanceof User) {
 
            User other = (User) o;
 
            if (this.longVal != other.longVal) { //crash ici
                return false;
            }
 
            if (this.stringVal != null) {
                if (!this.stringVal.equals(other.stringVal)) {
                    return false;
                }
            }
 
            if (this.stringVal == null && other.stringVal!=null) {
                    return false;
            }
 
            return true;
        }
        return false;
    }
une idée?