-
293 votesanswersviews
为什么Java 8接口方法中不允许“final”?
Java 8最有用的功能之一是接口上的新 default 方法 . 基本上有两个原因(可能有其他原因)为什么会被引入: 提供实际的默认实现 . 示例:Iterator.remove() 允许JDK API演变 . 示例:Iterable.forEach() 从API设计者的角度来看,我希望能够在接口方法上使用其他修饰符,例如 final . 这在添加便捷方法时非常有用,可以防止&qu... -
199 votesanswersviews
在Java 8接口方法中不允许“synchronized”的原因是什么?
在Java 8中,我可以轻松地写: interface Interface1 { default void method1() { synchronized (this) { // Something } } static void method2() { synchronized (Interfac...