views:

1292

answers:

3

I used the "pull interface" refactoring feature of Eclipse today to create an interface based on an existing class. The dialog box offered to create all the new methods of the new interface as "abstract" methods.

What would be the benefit of that?

I thought that the fact that you were allowed to declare interface methods as abstract was a superfluous and harmless feature of the language that is not particularly encouraged.

Why would Eclipse support such a style, or why would someone voluntarily choose to do so?

Clarification: I am not asking why interface methods are abstract, that is obvious. I am asking why one would explicitly choose to mark them as abstract since if they're in an interface they are abstract anyway.

+17  A: 

According to the Java Langauge Specification, the abstract keyword for interfaces is obsolete and should no longer be used. (Section 9.1.1.1)

That said, with Java's propensity for backwards compatability, I really doubt it will ever make a difference whether the abstract keyword is present.

EDIT: New and improved linkage.

jdmichal
That was my understanding (though I was not familiar with the specific JLS section). I'm wondering why Eclipse would offer me the option of creating an obselete marking...
Uri
Got me. Someone somewhere must of decided it was a desirable "feature" and put it in. You know, one of those wily open-source types :)
jdmichal
tsk tsk... Without a warning that it's obselete...
Uri
+3  A: 

According to JLS methods in interfaces are abstract by default, so the keyword is obsolete. Knowing this, I'd never use it to "avoid presentational clutter".

dhiller
+6  A: 

"The benefice of that" (adding abstract on interface methods declaration) in eclipse would be an old compatibility issue with jdt eclipse compiler in jdk1.3

Since 1.4, jdk libraries are no longer containing default abstract methods (on abstract classes implementing interfaces).
This is fooling the Eclipse 1.3 compiler diagnosis since their implementation is relying on their existence.
Note that Javac 1.3 would refuse altogether to perform against 1.4 libraries (using -bootclasspath option).

Since the Eclipse compiler is likely to be in 1.4 compliance level (see Workbench>Preferences>Java>Compiler>JDK Compliance), or use at least 1.3 class libraries if using 1.3 compliance mode, the presence of "abstract" is not required in most of the current eclipse projects.

VonC
Good find. So it's functionality to work around a no-longer existent problem in the Eclipse compiler.
jdmichal
@jdmichal: exactly, and it is also a more accurate answer to Uri's question.
VonC