This is not quite true when it comes to interfaces (which is the case here). Static methods in interfaces are never inherited, so declaring a non-static method with the same signature as a static method from a superinterface is possible. This, for example, is fine:You cannot override a static method with a non-static method and vice-versa.
Code: Select all
interface Readable {
static String getAction() {
return "read";
}
}
interface ReadableInEnglish extends Readable {
default String getAction() {
return "read in English";
}
}
Code: Select all
interface Readable {
static String getAction() {
return "read";
}
}
interface ReadableInEnglish extends Readable {
String getAction();
}
Code: Select all
interface Readable {
default String getAction() {
return "read";
}
}
interface ReadableInEnglish extends Readable {
static String getAction() { //won't compile, can't override default method with static method
return "read in English";
}
}
Code: Select all
interface Readable {
String getAction();
}
interface ReadableInEnglish extends Readable {
static String getAction() { //won't compile, can't override abstract method with static method
return "read in English";
}
}