我应该选择==或eq来比较EL中的字符串吗? [英] Should I choose == or eq for comparing string in EL?

查看:181
本文介绍了我应该选择==或eq来比较EL中的字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

== eq 使用EL进行相同的结果来进行字符串比较测试:

== 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>

我应该使用 eq 吗? == 仅适用于整数吗?但它也适用于字符串。 AFAIK == 测试hashCodes是否相等, eq 表示有意义的不同。

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".

另一个问题 == eq 做同样的事情。

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

有吗没有区别吗?与我说的不同之处在于: == 查看hashCode和 eq 查看执行情况等于(...)

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(...).

推荐答案

他们都是相同。我在EL中使用 eq ,因为它更像句子一样可读。

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

这篇关于我应该选择==或eq来比较EL中的字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆