直接上代码吧,下面这段代码在jdk5可以编译通过
abstract class TestOverride {
abstract void toOverride() throws Exception;
}
public class TestInterfaceOverride {
public static void main(String[] args) throws Exception {
TestOverride testOverride = new TestOverride() {
@Override
public void toOverride() throws Exception {
System.out.println("xxx");
}
};
testOverride.toOverride();
}
}
下面这段代码在jdk5下编译不过,提示“The method toOverride() of type new TestOverride(){} must override a superclass method”
interface TestOverride {
void toOverride() throws Exception;
}
public class TestInterfaceOverride {
public static void main(String[] args) throws Exception {
TestOverride testOverride = new TestOverride() {
@Override
public void toOverride() throws Exception {
System.out.println("xxx");
}
};
testOverride.toOverride();
}
}
但是两段代码在jdk6以后都可以编译通过。