Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Eclipse mark interface methods public abstract?

When using Eclipse's "Extract Interface" refactoring, it will declare the methods public abstract by default. Why? public modifier on an interface is completely redundant and abstract also seems meaningless on an interface declaration.

like image 526
vertti Avatar asked Jan 29 '13 07:01

vertti


1 Answers

These keywords are indeed redundant. I personally wouldn't use them in this context, but I can see why someone might prefer to include them.

The JLS explicitly discourages this practice:

It is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a method declared in an interface.

In my version of Eclipse (Juno SR1), there are two options in the Extract Interface dialog:

  • declare interface methods as public;
  • declare interface methods as abstract.

If you untick them, Eclipse should no longer include the two keywords when you extract an interface.

There is a pending Eclipse bug report to clean up the redundant modifies.

like image 94
NPE Avatar answered Sep 19 '22 01:09

NPE