Code-Life icon indicating copy to clipboard operation
Code-Life copied to clipboard

interface的method和interface中abstract method区别

Open Draymonders opened this issue 3 years ago • 0 comments

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

Draymonders avatar Oct 21 '20 10:10 Draymonders