Can anyone help me to find what's wrong with this piece of code run in jdk1.6.0_45?
public class App {
public static void main(final String args[]) {
SortComparator<String, Integer> a = build();
}
private static <T, O extends Comparable<O>> SortComparator<T, O> build() {
return null;
}
public class SortComparator<T, O extends Comparable<O>> implement Comparator<T> {
@Override
public int compare(final T o1, final T o2) {
return 1;
}
}
}
This is a pure Java language question. Why it does not compile? Why it does in Eclipse?
- If I change
SortComparator<String, Integer>
toMap<String, Integer>
it compiles. - If I add the parameter Class< O> arg as an argument of build it compiles.
- If I add App. build() to the call it compiles.
Console output:
incompatible types; no instance(s) of type variable(s) T,O exist so that build<T,O> conforms to SortComparator<java.lang.String,java.lang.Integer>
Versions
- Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
- Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
- Default locale: es_ES, platform encoding: Cp1252
- OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"