这是jdk 8 后有的,7 没有
public interface InterfaceA {
/**
*
* 默认方法可以不强制重写,并且在一个类继承接口后可以直接使用接口中的默认方法
*
*
*
*/
public default void prints(){
System.out.println("print ====");
}
static void showStatic() {
System.out.println("showStatic===");
}
}
public class InterfaceAImpl implements InterfaceA{
static void ste(){
System.out.println("sss");
}
public static void main(String[] args) {
InterfaceAImpl interfaceA = new InterfaceAImpl();
InterfaceA in = new InterfaceAImpl();
in.prints();
// in.showStatic(); 这里不行,不能这样调用会报错 必须要InterfaceA.showStatic();
interfaceA.ste();
interfaceA.prints();
}
}
原文:https://www.cnblogs.com/gaohq/p/14800149.html