0

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?

bjedrzejewski
  • 2,378
  • 2
  • 25
  • 46

1 Answers1

2

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:

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • I know I can use equals, but my question is to bypass it and use '==' instead. If this is not possible, then I will wait a bit more (in case someone has a genius answer) and accept your answer. – bjedrzejewski Oct 21 '13 at 16:01
  • @jedrus07 maybe if your post your actual problem you could get a more accurate answer. – Luiggi Mendoza Oct 21 '13 at 16:05
  • @LuiggiMendoza Mendoza The **link** *Java EE tutorial: Expression Language: Operators* is **broken**. Please update it. – OO7 May 14 '15 at 13:25
  • @OO7 link updated. Thanks. I recommend you to update links whenever you can, not only here but in other Q/As as well. – Luiggi Mendoza May 14 '15 at 14:38
  • @Luiggi Mendoza Ok I'll. – OO7 May 15 '15 at 05:00