The error you are referring to states is that it cannot guess the parameter of the generic type that you omitted. The reason for this is because the constructor you are using is unknown. This is unknown because the second argument is not a comparator. Your comparator must implement the java.util.Comparator interface in order to be safe for the constructor to accept.
public class TComparator<String> implements Comparator<String> { @Override public int compare(String arg0, String arg1) {
Also note: in the Comparator interface, the corresponding method is called compare , not compareTo .
General advice, I have to agree with Louis Wasserman, for the two arguments given, the comparator should always return the same result and not depend on the state of the application. Itβs too easy not to think about a case, and the application is ultimately messed up.
source share