Steve Losh发布 了以下 Clojure 片段:
; Integers and Longs are equal.
(= (Integer. 1) (Long. 1))
true
; Even negative ones.
(= (Integer. -1) (Long. -1))
true
; When you use them as keys in maps, the maps are still equal.
(= {(Integer. 1) :foo} {(Long. 1) :foo})
true
(= {(Integer. -1) :foo} {(Long. -1) :foo})
true
; When you use positive numbers as keys to sets, they're also equal.
(= #{(Integer. 1)} #{(Long. 1)})
true
; But negative ones aren't. But only in sets. Maps are fine. lol.
(= #{(Integer. -1)} #{(Long. -1)})
false
这种行为的原因是什么?它被认为是缺陷还是存在“形式逻辑”/集合论的原因,为什么(Integer. -1)
不等于(Long. -1)
持久集合?