public interface Expression {
}
public interface ArithmeticExpression extends Expression {
}
public class StaticMethodDemo {
public static void print(Expression e) {
System.out.println("StaticMethodDemo");
}
public static List<Expression> convert(
Collection<? extends Expression> input) {
return null;
}
}
public class StaticMethodChild extends StaticMethodDemo {
public static void print(ArithmeticExpression e) {
System.out.println("StaticMethodChild");
}
public static List<ArithmeticExpression> convert(
Collection<? extends ArithmeticExpression> input) {
return null;
}
}
Above code compiles in java 5 but not in java 7 why? In java 7 it gives "Name clash: The method convert(Collection) of type StaticMethodChild has the same erasure as convert(Collection) of type StaticMethodDemo but does not hide it"
Besides stonedsquirrel's answer, even if the methods were not static, you would get the same error.
This is because of Type Erasure, you would be trying to override convert with an incompatible type.
Check the following answer for a nice explanation.
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