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

后端 未结 1 2032
小鲜肉
小鲜肉 2021-01-26 01:16

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

1条回答
  •  时光说笑
    2021-01-26 01:42

    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

    0 讨论(0)
提交回复
热议问题