Java抽象接口 [英] Java abstract interface

查看:129
本文介绍了Java抽象接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个例子(在java中编译)

Consider an example (which compiles in java)

public abstract interface Interface {
    public void interfacing();
    public abstract boolean interfacing(boolean really);
}

为什么接口必须声明抽象?是否有适用于抽象接口的其他规则?

Why is it necessary for an interface to be "declared" abstract? Is there other rules that applies with an abstract interface?

最后:如果 abstract 已经过时,为什么它包含在Java中?是否有抽象接口的历史记录?

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

推荐答案


为什么接口必须是声明抽象?

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

不是。

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

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

接口及其方法隐式 abstract 并添加该修饰符没有区别。

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 apply. The method must be implemented by any (concrete) implementing class.


如果抽象已过时,为什么它包含在Java中?是否有抽象界面的历史记录?

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

有趣的问题。我挖出了第一个版本的JLS,甚至在那里它说 此修饰符已过时,不应在新Java程序中使用

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".

好的,进一步深入挖掘 ...在点击多个断开的链接后,我设法找到原始的副本 Oak 0.2 规范(或手册)。我必须说非常有趣的阅读,总共只有38页! : - )

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! :-)

在第5节接口中,它提供了以下示例:

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

public interface Storing {
    void freezeDry(Stream s) = 0;
    void reconstitute(Stream s) = 0;
}

在保证金中显示


将来,在接口中声明方法的= 0部分可能会消失。

假设 = 0 abstract 关键字取代,我怀疑 abstract 在某些时候是接口方法必不可少的!

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

相关文章: Java:抽象接口和抽象接口方法

这篇关于Java抽象接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆