在EE 6 JSF EL中是否存在与Java相当的'==' [英] Is there an equivalent of '==' from Java in EE 6 JSF EL
问题描述
我正在使用Primefaces 3.4在JSF 2中工作,我找到了一个例子,其中我的xhtml中的'=='在Java中的行为与'=='不同。我在Java EE 6文档中找不到'=='运算符的详细信息。它到底是做什么的? EL中的对象是否有等效的Java'=='?
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?
推荐答案
EL中的对象是否有等效的Java'=='
Is there an equivalent of Java '==' for Objects in EL?
看起来不是,但你真的不需要它。 EL ==
(和 eq
)将使用等于
比较对象引用时的方法,它已经支持 null
比较。如果你的类碰巧没有覆盖等于
,那么它将使用 Object#equals
以Java结尾 ==
进行相等检查。
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;
}
更多信息:
- Java EE tutorial: Expression Language: Operators
这篇关于在EE 6 JSF EL中是否存在与Java相当的'=='的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!