Java抽象接口 [英] Java abstract interface

查看:28
本文介绍了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.
}

接口及其方法是隐式的抽象,添加该修饰符没有任何区别.

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"部分可能会消失.

假设 =0abstract 关键字取代,我怀疑 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天全站免登陆