关于Abstract Interface与Interface之间的区别,从网查了很多的资料,大部分都是讲这两个之间没有任何的区别。因为,Interface本身就是abstract的的。
以下是Java权威书籍中关于这个问题的论述:
《Java in nutshell》
——"All methods of an interface are implicitly abstract, even if the abstract modifer is omitted"
《Thinking in java》
——"the abstract keyword, which allows you to create one or more methods in a class that have no definations——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."
——“Every interface is implicitly abstract, This modifier is obsolete and should not be used in new Java programs.”
所以结论就是:
interface已经隐含了abstract,interface与abstract interface的作用是一样的。
至于我们看到的abstract interface这样的描述,主要是由反编译器造成的,比如:
Cloneable接口,当我们在eclipse中利用反编译插件查看其源代码时,就会发现,
package
java.lang;
public
abstract
interface
Cloneable
{
}
但是,去翻看JDK源码时,却并没有发现abstract关键字,
package
java.lang;
public
interface
Cloneable
{
}
因此,我们可以确定在Java中是没有abstract interface这种用法的,虽然编译器允许通过了,但是在编程中还是应该尽量避免这种写法。