public int compareTo(ListItem item) {
if(item!=null) {
return ((String) super.getValue()).compareTo((String) item.getValue());
}
Run Code Online (Sandbox Code Playgroud)
我的程序基于抽象类概念。
如何java.lang.ClassCastException:
在我的程序中解决这个
问题?
为什么我们在 HashMap 和 HashSet 中使用 equals() 方法而不实现比较器接口?我在上面的概念中看到了一些示例程序。但是没有比较器接口,他们使用 equals() 和 hashcode() 方法。我的问题是,我们可以在没有比较器接口的情况下使用这些方法吗?我们还可以使用具有可比接口的 equals() 和 hashcode() 以及 compareTo() 方法吗?