Consider the following interface:Therefore, synchronized keyword can be applied only to a non-abstract method or a block of code appearing in a method or static or instance initialization blocks.
Code: Select all
public interface Synchronizable {
static void sync() {
synchronized (Synchronizable.class) { //no problem!
}
}
static synchronized void deSync() { //will not compile!
}
default synchronized void defaultSync() { //will not compile!
}
}
Finally,
is not a valid statement anymore since Java 8!All methods in an interface are implicitly abstract.
Kind regards,
Martijn