Java – the comparator must override superclass methods

I'm making a treemap < < string, string >, and hope to arrange it in descending order I created the following Comparators:

Comparator<String> descender = new Comparator<String>() {

    @Override
    public int compare(String o1,String o2) {
        return o2.compareTo(o1);
    }
};

I built a treemap as follows:

myMap = new TreeMap< String,String>(descender);

However, I received the following error:

The method compare(String,String) of type new Comparator<String>(){} must override a superclass method

I've never completely touched generic drugs. What did I do wrong?

Solution

Your eclipse project is obviously set to Java 1.5 Interface methods do not support @ override annotation Delete the comment or fix the compliance level of the project to Java 1.6

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>