Draymonders / Code-Life

The marathon continues though.
27 stars 3 forks source link

interface的method和interface中abstract method区别 #114

Open Draymonders opened 3 years ago

Draymonders commented 3 years ago

Origin

看到了Runnable, RunnableFuture源码

public interface Runnable {
    public abstract void run();
}

public interface RunnableFuture<V> extends Runnable, Future<V> {
    void run();
}

普通声明的方法和abstract的方法有什么区别呢?

其实无论接口和接口中的方法如何声明,都是抽象的。即使在声明接口时,并没有用abstract修饰,但是在编译的时候编译器会自动加上abstract。所以根本没有实质意义上的区分,只不过在写法上有所不同而已。接口中方法都是抽象的,这个无论用不用修饰符abstract都是一样的。

Reference

https://blog.csdn.net/xw13106209/article/details/6926265