Why is it necessary for an interface to be "declared" abstract?

本文讨论了Java中接口声明为抽象的必要性,指出接口及其方法默认即为抽象,使用abstract关键字并无实际作用。此外,文章还追溯了Java语言规范的历史,解释了为何保留此关键字。
 

Why is it necessary for an interface to be "declared" abstract?

It's not.

public abstract interfaceInterface{
       \___.__/|'---->Neither this...

public void interfacing();

public abstract boolean interfacing(boolean really); \___.__/|'----> nor this, are necessary.}

Interfaces and their methods are implicitly abstract and adding that modifier makes no difference.

Is there other rules that applies with an abstract interface?

No, same rules applies. The method must be implemented by any (concrete) implementing class.

If abstract is obsolete, why is it included in Java? Is there a history for abstract interface?

Interesting question. I dug up the first edition of JLS, and even there it says "This modifier is obsolete and should not be used in new Java programs".

Okay, digging even further... After hitting numerous broken links, I managed to find a copy of the original Oak 0.2 Specification (or "manual"). Quite interesting read I must say, and only 38 pages in total! :-)

Under Section 5, Interfaces, it provides the following example:

public interface Storing{

  void freezeDry(Stream s)=0;
  
  void reconstitute(Stream s)=0;
}

And in the margin it says

In the future, the " =0" part of declaring methods in interfaces may go away.

Assuming =0 got replaced by the abstract keyword, I suspect that abstract was at some point mandatory for interface methods!

refer from:http://stackoverflow.com/questions/7202616/java-abstract-interface

转载于:https://www.cnblogs.com/silentjesse/archive/2013/05/31/3109756.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值