抽象接口——abstract interface???

关于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这种用法的,虽然编译器允许通过了,但是在编程中还是应该尽量避免这种写法。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值