关于Abstract interface的问题。

今天在阅读Struts 2 的 interceptor 代码时,发现里面的接口是这样写的:

public abstract interface Interceptor extends Serializable
{
public abstract void destroy();

public abstract void init();

public abstract String intercept(ActionInvocation paramActionInvocation)
throws Exception;
}

很在意为什么是 public abstract interface. 于是上网查找了一番,在StackOverflow论坛发现如下内容:

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.

所以证明,abstract interface 是已经过时的写法,不过正是因为这样,也让我们更深入的理解到了interface的过去。


原文地址:https://www.cnblogs.com/rainisic/p/2344041.html