对于BigDecimal类在HashSet和TreeSet中 new BigDecimal("1.00") new BigDecimal("1.0") 在HashSet容器中这是两个实例,因为BigDecimal类的equals()方法来比较是不相等的, 但是在TreeSet容器中这是一个实例,因为TreeSet会调用BigDecimal实现的compareTo()方法,实际上BigDecimal的compareTo()方法对上述两个实例来讲是相等的 这里涉及到一个…
本文参考 本篇文章参考自<Effective Java>第三版第十条"Obey the general contract when overriding equals" the conditions when each instance of the class is equal only to itself Each instance of the class is inherently unique -- 类的每一个实例本就彼此不同,例如Thread类,每一个线程仅和自…