一个关于Java中SortedMap定义的问题
伊谢尔伦
伊谢尔伦 2017-04-18 09:49:18
[Java讨论组]

一个关于Java中SortedMap定义的问题

在SortedMap接口的解释中有这么一段话:

 * 

Note that the ordering maintained by a sorted map (whether or not an * explicit comparator is provided) must be consistent with equals if * the sorted map is to correctly implement the Map interface. (See * the Comparable interface or Comparator interface for a * precise definition of consistent with equals.) This is so because * the Map interface is defined in terms of the equals * operation, but a sorted map performs all key comparisons using its * compareTo (or compare) method, so two keys that are * deemed equal by this method are, from the standpoint of the sorted map, * equal. The behavior of a tree map is well-defined even if its * ordering is inconsistent with equals; it just fails to obey the general * contract of the Map interface.

请问这段话是什么意思?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
黄舟

就是要求map里面的对象,做compareTo和equals来比较的时候结果是一致的。比如compareTo返回0,那么equal一定是true。但有的对象可不是这样的,比如BigDecimal

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号