大家在平時作業學習中不知道用執行緒用的多不多,反正在面試里面你隨時都在用且6的飛起
不知道大家有沒有注意到這樣一個問題
@FunctionalInterface
public interface Runnable {
public abstract void run();
}
如果你沒發現有什么不妥
我就再貼一段代碼
@FunctionalInterface
public interface Callable<V> {
V call() throws Exception;
}
發沒發現,Runnable里面介面定義方法冗余了 public abstract ,我有點納悶
于是我找找找,找到這么一段話,來自于java language specification
Every method declaration in the body of an interface is implicitly abstract, so its body is always represented by a semicolon, not a block.
Every method declaration in the body of an interface is implicitly public.
For compatibility with older versions of the Java platform, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces.
It is permitted, but strongly discouraged as a matter of style, to redundantly specify the public modifier for interface methods.
說白了就是介面中的方法默認是 public abstract 的,java允許你添加這兩個修飾符,但不鼓勵哈,至于他自己為什么要這么做,maybe是為了兼容舊版本的Java平臺
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/257050.html
標籤:其他
上一篇:行遠自邇,不負韶華!2020年度博客之星TOP 20榜單揭曉
下一篇:Java-單例模式
