Should I choose == or eq for comparing string in EL?

Niklas R. picture Niklas R. · May 29, 2012 · Viewed 99k times · Source

== and eq give the same result using EL to do my string comparison tests:

    <c:if test="${person.sokande_i == 'endast_usa'}">Endast USA</c:if>
    <c:if test="${person.sokande_i == 'alla'}">Alla länder</c:if>
    <c:if test="${person.sokande_i == 'alla_utom_usa'}">Alla utom USA</c:if>

Should I use eq instead? Is == for integers only? But it works also for strings. AFAIK == test whether hashCodes are equal and eq means "meaningfully different".

Another question says == and eq do the same thing.

Is there no difference here? IS not the difference the one I'm stating: == looks at the hashCode and eq looks at the implementation of equals(...).

Answer

adarshr picture adarshr · May 29, 2012

They're both the same. I use eq in EL as it is more readable like a sentence.