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

 NE丰胸茶urghx 发布于 2022-10-26 14:42

一个关于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.

请问这段话是什么意思?

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

    2022-10-27 01:14 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有