java.lang.ClassCastException: cannot be cast to java.lang.Comparable是怎么回事

当我们遇到这个异常时,当我们点击错误提示时,他会跳到这行代码,肯定是因为treeMap或者treeSet不知道如何put,如图: 第一次put时,因为treeMap或者treeSet为空,所以不需要比较,即不会报错。但是当第二次put时,treeMap(或者treeSet)为了确保他是有序的就必须比较,这个时候发现这两个key根本无法比较,则抛出该异常错误。 解决方法 首先,根据cannot be
相关文章
相关标签/搜索