I found a lot of problems in my project when I switched from an Eclipse build to a maven build. I am using the 2.5.1 compiler plugin.
JDK open-JDK-7
I highlighted the problem in a new project and stopped it:
public class Test {
public static void main(String[] args) {
List<String> list = newList();
for(String name : sort(newList(list))) {
System.out.println(name);
}
}
public static <T> List<T> newList() {
return new ArrayList<T>();
}
public static <T, E extends T> List<T> newList(Collection<E> list) {
return new ArrayList<T>();
}
public static <T> List<T> sort(List<T> list) {
return list;
}
}
This fails to compile using javaC (but works in Eclipse), indicating the following error:
[ERROR] Failed to fulfill the goal org.apache.maven.plugins: maven-compiler-plugin: 2.5.1: compile (by default compilation) when testing a project: compilation failed
[ERROR] / home / username / workspaces / projectx43 / test /src/main/java/test/Test.java:[11,24] error: incompatible types
And this will work:
public class Test {
public static void main(String[] args) {
List<String> list = newList();
for(String name : sort(newList(list))) {
System.out.println(name);
}
}
public static <T> List<T> newList() {
return new ArrayList<T>();
}
public static <T> List<T> newList(Collection<? extends T> list) {
return new ArrayList<T>();
}
public static <T> List<T> sort(List<T> list) {
return list;
}
}
, E , , T. , javac, . .
: OpenJDK 7 - SunJDK 7? Sun JDK 7 - JDK 8. .
PS: Eclipse JavaC + Generics, , .