gpt4 book ai didi

java - @override 在 java 中如何工作

转载 作者:行者123 更新时间:2023-12-01 11:31:09 25 4
gpt4 key购买 nike

我看到@override注释是标记注释。编译器如何知道如何处理这个注释?检查方法是否真的重写父类(super class)方法的逻辑在哪里?我想它考虑了所有注释,因为没有逻辑

最佳答案

standard documentation很好地回答了这个问题。

@Override @Override annotation informs the compiler that the element is meant to override an element declared in a superclass. Overriding methods will be discussed in Interfaces and Inheritance.

// mark method as a superclass method
// that has been overridden
@Override
int overriddenMethod() { }

While it is not required to use this annotation when overriding a method, it helps to prevent errors. If a method marked with @Override fails to correctly override a method in one of its superclasses, the compiler generates an error.

关于java - @override 在 java 中如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30366258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com