任何相当于 @Override 的注释用于覆盖(隐藏)静态方法?
正如此处所解释的,在java中静态方法不是被子实现覆盖但隐藏,
这意味着您不能将 @Override 注释与它们一起使用,
以下代码
@Override
public static void test(String value1, String value2) {
会给出此编译器错误。
The method test(String, String) of type Child must override or implement a supertype method Child.java
是否有一些等效的注释可以用来确保我的类“隐藏”父类中的现有静态方法?
as it is explained here, in java static methods are not overridden but hidden by child implementations
that means that you can't use @Override annotations with them
the following code
@Override
public static void test(String value1, String value2) {
gives this compiler error.
The method test(String, String) of type Child must override or implement a supertype method Child.java
is there some equivalent annotation that I could use to make sure my class is "hiding" an existing static method from parent class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个简单的问题:不。
查看标准编译器注释列表< /a>
This is an easy one: No.
Check out the list of standard compiler annotations
我不知道您可以添加任何注释。但只需创建具有完全相同的名称和输入(相同的方法签名)的方法就可以隐藏它。唯一确定的方法是确定超类方法的细节,然后也许测试你的方法......这就是我能想到的。我能想到的唯一其他注释是抑制警告,这与我想象的相反。每当我隐藏这样的方法时,我通常都会从 IDE 收到警告,告诉我正在隐藏另一个方法。
I am not aware of any annotations that you can add. But simply creating the method with the exact same name and inputs (the same method signature) should hide it. The only way to know for sure is to know the details of the superclass method for sure, and then perhaps test your method... Thats all I can think of. The only other annotations I can think of would be to suppress warnings which would be the opposite of what you want I imagine. Whenever I hide a method like this I generally get a warning from my IDE telling me that I am hiding another method.