【发布时间】:2012-12-03 16:06:34
【问题描述】:
到目前为止,我的理解是== 是.equals() 的运算符重载。然而,我最近发现
new Integer(1) == new Long(1) // returns true
而
new Integer(1).equals(new Long(1)) // returns false
所以我猜== 不完全是.equals() 的简写,那么它是如何确定相等的呢?
【问题讨论】:
-
在使用具有长数据库 ID 的 GORM 时,这继续困扰着我。来自 JSON 的请求生成的整数值产生如下行为:groovy:000> m = [1L : 'foo'] ===> [1:foo] groovy:000> m.containsKey(1L) ===> true groovy:000 > m.containsKey(1) ===> 错误
标签: groovy