abstract interface, why to specify abstract (an interface is abstract !!)?

In some packages, we find some interfaces declared as abstract.
For exemple:
public abstract interface Synchronization

An interface is a file of abstract methods (signatures only), so why to specify abstract?
Is it necessary?
Does it mean something?
Who is Participating?
Jim CakalicConnect With a Mentor Senior Developer/ArchitectCommented:
The Java Language Spec 2.0 advises "Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs." With respect to methods declared in an interface, it goes on to state, "For compatibility with older versions of Java, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces."

So using abstract in the definition of an interface in no way distinguishes it from an interface _not_ declared with the abstract modifier. There is no difference between the two.

Evidently, sometime in the dim and distant path, it was required that interfaces and defined methods be declared using the abstract keyword. As it was eventually recognized that this declaration was redundant, that requirement was relaxed. However, for purposes of compatibility with legacy releases of the JDK, the syntax is still acceptable to modern compilers. Seeing as this change came about even prior to the publication of the JLS 1.0 in 1996, it is highly unlikely, although possible, that you would run into a compiler that required the abstract keyword in the declaration of either an interface or its methods.

Best regards,
Jim Cakalic
"All methods of an interface are implicitly abstract, even if the abstract modifier is omitted." Java in a Nutshell

So, it is not necessary, and does not mean anything to an interface.
Hi Webski

U can create an instance for an Interface that is quite possible. But for a abstract interface u cann't. That is why some interface cann't have instance that is why to avoid them there use abstract before it.

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

webaskiAuthor Commented:
Hi Shyam,
How can you create an instance of an interface, when you only have the signatures of the methods in it?
It is not possible... Is it?
Jim CakalicSenior Developer/ArchitectCommented:
You're right, webaski, you cannot create an instance of an interface in the same way you create an instance of a class. For example, the following will not work:

    Serializable x = new Serializable();

Being _inherently_ abstract, you cannot directly create instances of an interface, just as you cannot construct instances of an abstract class. But you might, through an anonymous inner class, declare a class that implements the interface, define that class's implementation, and construct an object of the new class.

    Serializable x = new Serializable() { };

This _looks_ a lot like creating an instance of an interface but is _completely_ different.

Best regards,
Jim Cakalic
webaskiAuthor Commented:
Well, it works because there is no method in the Serializable interface... Try with WindowListener for example, it won't compile.

WindowListener x = new WindowListener() { };
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
Jim CakalicSenior Developer/ArchitectCommented:
Recommendation: points to jim_cakalic
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

[points to jim_cakalic]

Please leave any comments here within the next seven days.
EE Cleanup Volunteer
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.