JDK8接口加强-1
interface demo{
public default void speak(String text){ //JDK1.8新特性,支持定义default修饰的方法,并定义其方法体
System.out.println(text);
}
public static test getTest(){ //JDK1.8新特性,支持定义静态的方法与方法体
return new test();
}
public void show();
}
class test implements demo{
public void show(){
System.out.println("Hello");
}
}
public class interfacePlus{
public static void main(String[] args){
test t = demo.getTest();
t.show();
t.speak("OK");
}
}
Console:
Hello
OK