public class Draw<T extends Print> (Print is a interface)
其他类:
public interface Print {
static void info(String message) {
System.out.println("failed");
}
}
public class Test implements Print {
static void info(String message) {
System.out.println(message);
}
}
当使用new Draw<Test>()
并尝试运行T.info("Test");它只打印"失败">
我做错了什么吗?
静态方法不会被重写。你必须调用Test.info来调用你的方法。静态方法位于接口上,因为它是放置它们的方便位置。这不是你可以重写的东西,它也不是默认功能。默认方法不是静态的,必须使用默认关键字。
如果你想要多态,使用实例方法,而不是静态方法。