对于jdk1.8 的 接口中default方法的疑惑

接口中的default方法可能会使得接口被破坏掉

如下代码:

 
 
public interface _No {

	
	default void run3() {
		run2();
	}
	
	default void run2() {
		System.out.println("run2");
	}
	
	
	static void run1() {
		System.out.println("static");
	}
}
 
 
public class _No1 implements _No{


	public void run3() {
		System.out.println("run3");
	}
	
	
	public void run2() {
		System.out.println("run2");
	}
	
	public static void main(String[] args) {
		_No n = new _No1();
		n.run3();
	}
}

当子类方法run3()覆盖掉接口的run3()    接口中的run3()失效    ,当在接口的所有default方法中使用run3()的时候,全部改为打印

这种方式是否对接口造成了破坏呢?


猜你喜欢

转载自blog.csdn.net/perfect_red/article/details/80504221