Any annotation equivalent to @Override to override (hide) static methods?

as explained here , in java, static methods are not overridden, but hidden using child implementations

this means you cannot use @Override annotations with them

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 an equivalent annotation that I could use to make sure my class β€œhides” the existing static method from the parent class?

+4
source share
2 answers

I am not aware of any annotations you can add. But just creating a method with exactly the 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 for sure, and then maybe test your method ... That's all I can think of. The only other annotations I can think of are to suppress warnings that would be the opposite of what you want to present. Whenever I hide a method like this, I usually get a warning from my IDE telling me that I am hiding another method.

+1
source

It is easy: No.

Check the list of standard compiler annotations

+3
source

Source: https://habr.com/ru/post/1345265/


All Articles