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;
}
}
上面的代码在 java 5 中编译,但在 java 7 中不编译,为什么?在 java 7 中,它给出了“名称冲突:StaticMethodChild 类型的方法 convert(Collection) 与 StaticMethodDemo 类型的 convert(Collection) 具有相同的擦除,但不隐藏它”