Is there an equivalent of '==' from Java in EE 6 JSF EL

醉酒当歌 提交于 2019-12-04 06:38:30

问题


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


来源:https://stackoverflow.com/questions/19498926/is-there-an-equivalent-of-from-java-in-ee-6-jsf-el

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!