我知道在Java中,静态方法就像实例方法一样继承,不同之处在于,当重新声明它们时,父实现被隐藏而不是被覆盖.好吧,这很有道理.但是,Java教程指出了这一点
接口中的静态方法永远不会被继承.
为什么?常规和接口静态方法有什么区别?
当我说静态方法可以继承时,让我澄清一下我的意思:
class Animal {
public static void identify() {
System.out.println("This is an animal");
}
}
class Cat extends Animal {}
public static void main(String[] args) {
Animal.identify();
Cat.identify(); // This compiles, even though it is not redefined in Cat.
}
Run Code Online (Sandbox Code Playgroud)
然而,
interface Animal {
public static void identify() {
System.out.println("This is an animal");
}
}
class Cat implements Animal {}
public static void main(String[] args) {
Animal.identify();
Cat.identify(); // This does not compile, because interface …Run Code Online (Sandbox Code Playgroud) 到目前为止,我一直在研究Java 7,最近又转到了Java-8,令人惊讶的是您可以在Java-8接口中添加方法。
到目前为止一切都很好。。。。
现在,我的问题是,这logging是任何开发中必不可少的部分,但是似乎lombok.extern.slf4j不允许您log通过接口方法添加内容,因为只允许在classes和上使用enums。
您如何使用log接口方法(如果通过lombok或这是唯一方法?)?还是不应该记录接口方法?我在这里想念什么?
PS:目前我有工作System.out.println....是啊...这就是小白 :)