Why I have to fully qualify the java.lang.String in the static fields List
public static class MyComparator<String> implements Comparator<String> {
public static List sortOrder;
public static List<Integer> sortOrder2;
public static List<java.lang.String> sortOrder3; // works!
public static List<String> sortOrder4; // <-Compiler error only in this line
@Override
public int compare(String s1, String s2) {
// TODO
return -1;
}
}
Error is "Cannot make a static reference to the non-static type String"
You have defined a generic type parameter String
that is the same name as the class, so String
refers to your parameter, while java.lang.String
still works.
Remove it from your class, but keep it in the implements
clause.
public static class MyComparator implements Comparator<String> {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With