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 Java EE 6 documentation. What does it exactly do? Is there an equivalent of Java '==' for Objects in EL?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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:
- Java EE tutorial: Expression Language: Operators