views:

292

answers:

7

What's point of declaring an interface as abstract? Same thing for an interface method. Is there a point to it?

eg.

public abstract interface Presenter {
 public abstract void go(final HasWidgets container);
}
+2  A: 

Typically, you don't declare the interface, or its methods, as abstract. They are implicitly.

The methods are also public, so you can skip that also. :-)

KLE
+21  A: 

Interfaces and interface methods are implicitly abstract even if not declared as so. So there is no need to explicitly specify it.

notnoop
All interface methods are also implicitly `public`, making declaring them as such redundant as well.
matt b
The same goes for the "public" on the method: it's implicit and isn't needed.
Joachim Sauer
"public" makes it more explicit and is good for readability IMO. Abstract is pointless in this context.
Keith Rousseau
@Keith: not to start a fight, but what exactly is the different between "public" and "abstract" in front of a method here? Both are implicit and can't be changed. Why should one be written and the other one not?
Joachim Sauer
@Joachim: I would argue that not all developers would realize that an interface is public by default. I have always thought it to be good practice to fully qualify whether something is public/protected/private. By the definition of an interface it is abstract
Keith Rousseau
A: 

The default behavior of an interface is essentially equivalent to what you have in your example. Defining it as abstract is just redundant.

Zack
A: 

I think just verboseness, explicitness and consistency with the class syntax and semantics...

You don't have to, but maybe it could help if some reader of your code is distracted or not very versed in Java.

fortran
Isn't it the opposite (as this thread proves).If anyone is actually writing an interface they must know what an interface is. IMO this is more confusing.
Matt Wolfe
If the code is not for just yourself, you should write thinking in the others.
fortran
+2  A: 

Makes no difference - interfaces and interface methods are always abstract but you don't have to add the modifier (and interface methods are always public so you don't need the public modifier too).

From the JLS:

9.1.1.1 abstract Interfaces

Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs.

Andreas_D
+13  A: 

Where did you come across the chunk of code you have posted, any old java code base ?
This is what the JLS has to say :

9.1.1.1 abstract Interfaces
Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs.

9.4 Abstract Method Declarations
For compatibility with older versions of the Java platform, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces.

sateesh
A GWT 2.0 example :D
Sudhir Jonathan
+1 Very informative!
notnoop
+1 for referencing the spec!
Carl
@Sudhir, googling for the code chunk you posted I came across this mail thread where the same issue is discussed:http://osdir.com/ml/Google-Web-Toolkit/2010-01/msg00452.htmlAlso see:http://osdir.com/ml/Google-Web-Toolkit/2010-01/msg00516.html where probable explanation for the usage is mentioned. (to paraphrase: what was started as an abstract class might have been changed to interface with the earlier modifier not being removed)
sateesh
Hmmm... that would explain it.
Sudhir Jonathan
A: 

There is no point of declaring interface to be abstract. As the methods in the interface are abstract only.. One more thing abstract class can have both concrete and abstract methods but in the interface there should be only abstract methods.

giri
if I remember well, an interface can have concrete methods (static).
fortran