前一段用到Spring的ApplicationContext接口,查看它提供的方法,打开jar包,看到的信息如下:
发现interface前有个abstract,怎么还有抽象接口(abstract interface)一说,接口不都是抽象的吗,这样写难道还有什么特殊意义,很是纳闷。
上网查询一些资料,有的网友把一些有名的java书上写的关于接口的论述贴了出来:
在java in a nutshell里,
“All methods of an interface are implicitly abstract, even if the abstract modifier is omitted.”
在thinking in java里,
“the abstract keyword, which allows you to create one or more methods in a class that have no definitions—you provide part of the interface without providing a corresponding implementation, which is created by inheritors. The interface keyword produces a completely abstract class, one that provides no implementation at all.”
所以结论就是 abstract interface 就是interface,两者根本没有区别。
但是为什么他们要那样写啊,不是多此一举吗?是不是jar包中把隐含的abstract自动加上了呢,我又找到了源代码,果然,源代码中并没有abstract:
所以,结论就是:
interface已经隐含是abstract的,interface与abstract interface的作用是一样的,只是abstract interface是更完整的表示而已。
public abstract interface ApplicationContext extends ... {
public abstract ApplicationContext getParent();
...
}
发现interface前有个abstract,怎么还有抽象接口(abstract interface)一说,接口不都是抽象的吗,这样写难道还有什么特殊意义,很是纳闷。
上网查询一些资料,有的网友把一些有名的java书上写的关于接口的论述贴了出来:
在java in a nutshell里,
“All methods of an interface are implicitly abstract, even if the abstract modifier is omitted.”
在thinking in java里,
“the abstract keyword, which allows you to create one or more methods in a class that have no definitions—you provide part of the interface without providing a corresponding implementation, which is created by inheritors. The interface keyword produces a completely abstract class, one that provides no implementation at all.”
所以结论就是 abstract interface 就是interface,两者根本没有区别。
但是为什么他们要那样写啊,不是多此一举吗?是不是jar包中把隐含的abstract自动加上了呢,我又找到了源代码,果然,源代码中并没有abstract:
public interface ApplicationContext extends ListableBeanFactory, HierarchicalBeanFactory,
MessageSource, ApplicationEventPublisher, ResourcePatternResolver {
ApplicationContext getParent();
...
}
所以,结论就是:
interface已经隐含是abstract的,interface与abstract interface的作用是一样的,只是abstract interface是更完整的表示而已。