I am working in JSF 2 with Primefaces 3.4 and I found an example where \'==\' in my xhtml does not behave like \'==\' in Java. I could not find details for \'==\' operator in Ja
Is there an equivalent of Java '==' for Objects in EL?
Looks like it is not, but you don't really need it. EL ==
(and eq
) will use the equals
method when comparing object references, and it already supports null
comparison. If your class happens to not override equals
, then it will use Object#equals that ends using Java ==
for equality check.
If your class happens to override equals
method, make sure to write a good implementation. As example:
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (this == o) {
return true;
}
if (...) {
//add here the rest of the equals implementation...
}
return false;
}
More info: