Jake Wharton
Jake Wharton

Reputation: 76075

Suppress "The method does not override the inherited method since it is private to a different package."

How can I suppress the following error with the @SuppressWarning annotation?

The method Foo.trololo() does not override the inherited method from Bar since it is private to a different package

So far as I can tell the only way is to blanket the entire method with @SuppressWarning("all") which I would prefer not to do.


For clarification: The naming and scope of both methods is a deliberate choice and the two classes were deliberately put into different packages knowing the methods would not be visible to each other. I am merely looking to declare that I acknowledge what I am doing and would not like to be warned of it.

Upvotes: 3

Views: 3577

Answers (3)

Yosidroid
Yosidroid

Reputation: 2233

If you want to Suppress Warning a specific project, in the Eclipse Package Explorer, right click the project -> Properties -> Java Compiler -> Errors/Warnings then Check "Enable project specific settings" -> Name shadowing and conflicts then set "Method does not override package visible method" to "Ignore". Rebuild the project and warning will go away. Done!!

Upvotes: 0

aioobe
aioobe

Reputation: 420951

What it means (you probably know this already)

It means that, even though your method has the same name as a (non-private) method in the super class, it doesn't override that method.

Regarding the warning message

This is an Eclipse-specific warning. Nothing in the language spec says that it should produce this warning. It's an "IDE-specific feature" if you so like. Therefore there is no "generic" way of suppressing the message.

(Note for instance that javac does not produce this warning.)

How to disable this warning (in Eclipse)

(I know you are not looking for this, but some other visitor of this page may!)

To disable this warning, you go to

       Window -> Preferences -> Java -> Compiler -> Errors / Warnings

and set "Method does not override package visible method" to "Ignore".

Upvotes: 6

JB Nizet
JB Nizet

Reputation: 691635

This warning means that you have a package-private method trololo in Bar, and a trololo method in Foo, which extends Bar, but is not in the same package.

If your goal is to override the Bar.trololo method with Foo.trololo, then the Bar.trololo method must be made protected. If your goal is to have two different methods, it would be better to name the second one tralala to make it much clearer and avoid confusion.

Upvotes: 2

Related Questions