Java文档:从接口X继承的方法的含义是什么 [英] Java Documentation: What is meaning of 'methods inherited from interface X

查看:133
本文介绍了Java文档:从接口X继承的方法的含义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在这里遗漏一些基本的Java术语:

I must be missing some basic Java terminology here:

类可以扩展,因此它们的方法可以通过其子方式继承类。

Classes can be extended, therefore their methods can be inherited by their sub-classes.

接口可以实现。实现类必须实现所有接口的方法 - 接口本身不实现任何东西,只声明。

Interfaces can be implemented. An implementing class will have to implement all of the interface's methods - the interface itself does not implement anything, only declares.

那么,当我查看文档的时候怎么样HashSet( https://docs.oracle.com/ javase / 7 / docs / api / java / util / HashSet.html ),我看到接口 java.util中继承的方法列表。设置?

So, how come when I look at the documentation of HashSet (https://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html), I see a list of methods which are inherited from interface java.util.Set ?

推荐答案

我想你是从生成的JavaDoc HTML中引用这样的语句:

I guess you are referring to the statements like this from the generated JavaDoc HTML:


从接口java.util.Set继承的方法...

Methods inherited from interface java.util.Set ...

在这个意义上的继承意味着所讨论的方法的签名是继承的,但不一定是实现。原因很简单:在Java中,您通常不会查看第三方代码的实现,而只会查看带有签名和JavaDoc的接口。

Inheritance in this sense means that the signature of the methods in question is inherited, but not necessarily the implementation. The reason for that is simple: In Java you usually do not look into the implementations of third party code, but only into the interfaces with their signatures and JavaDoc.

所以,基本上,这些方法的签名继承自接口 Set 并在 HashSet 中实现AbstractSet 。因此,实际上它正在实现接口 Set

So, basically, the signatures of those methods are inherited from interface Set and implemented in the HashSet or AbstractSet. Hence, actually it is implementing the interface Set.

Sidenote :在Java 8中,您可以使用Interfaces实现方法,但这是一个不同的故事。

Sidenote: In Java 8, you can have Interfaces implementing methods, but that's a different story.

这篇关于Java文档:从接口X继承的方法的含义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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