2
Java 8接口方法中不允许“同步”的原因是什么?
在Java 8中,我可以轻松地编写: interface Interface1 { default void method1() { synchronized (this) { // Something } } static void method2() { synchronized (Interface1.class) { // Something } } } 我将获得在类中也可以使用的完整同步语义。但是,我不能synchronized在方法声明上使用修饰符: interface Interface2 { default synchronized void method1() { // ^^^^^^^^^^^^ Modifier 'synchronized' not allowed here } static synchronized void method2() { …