Compilers behave differently with a null parameter of a generic method
- by Eyal Schneider
The following code compiles perfectly with Eclipse, but fails to compile with javac:
public class HowBizarre {
public static <P extends Number, T extends P> void doIt(P value) {
}
public static void main(String[] args) {
doIt(null);
}
}
I simplified the code, so T is not used at all now. Still, I don't see a reason for the error.
For some reason javac decides that T stands for Object, and then complains that Object does not conform to the bounds of T (which is true):
HowBizarre.java:6: incompatible types; inferred type argument(s) java.lang.Number,java.lang.Object do not conform to bounds of type variable
(s) P,T
found : <P,T>void
required: void
doIt(null);
^
Note that if I replace the null parameter with a non-null value, it compiles fine.
Which of the compilers behaves correctly and why? Is this a bug of one of them?