• 1
  • 2
  • 3
  • 4
  • 5

高中生大学生毕业后必选职业路

Java不支持多继承,这是个BUG?

再怎么慎重都不为过

免费咨询 >
相关IT课程
Java不支持多继承,这是个BUG?
这些IT技术课程很火爆,你还在等什么?
怎么学好 学什么好 咋学快速
网络营销 以在线咨询为准 热招
HTML5定制班HTML5定制班热招 以在线咨询为准 热招
Python定制班Python定制班热招 以在线咨询为准 热招
软件测试就业班软件测试就业班热招 以在线咨询为准 热招
JAVA就业班JAVA就业班热招 以在线咨询为准 热招
UI设计定制班 以在线咨询为准 热招

全移动智能化教学设施

定义"高大上"

让你学习高薪技术专业轻松无忧快乐

  • Java开发工程师
  • PHP培训
  • web全栈工程师
  • 软件测试工程师
  • 人工智能培训
  • 云计算培训
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Java不支持多继承,这是个BUG?

你想不优秀,没门!

专业选择对了,努力才能不白费

大数据-Java不支持多继承,这是个BUG?
UI培训-Java不支持多继承,这是个BUG?
网络营销-Java不支持多继承,这是个BUG?
直播带货-Java不支持多继承,这是个BUG?
物联网-Java不支持多继承,这是个BUG?

Java不支持多继承,这是个BUG?


先从Java 8之前说起。要区分“声明多继承”与“实现多继承”。

Java是不允许“实现多继承”,简称不允许“多继承”。但是Java支持“声明多继承”——Java的接口的多继承——一个类可以实现多个接口(“继承”了多个接口上的方法声明),而一个接口可以继承多个接口(同样是“继承”了多个接口上的方法声明)。

 

接口只允许有方法声明而不允许有实现,因而不会出现像C++那样的实现多继承的决议问题;抽象类可以有方法实现,但要遵循Java类的单继承限制,也避免了实现多继承的问题。这是早期Java为了与C++区分开的一个决定。

至于早期Java为何要做这样的设计取舍,不必猜测,看看高司令老人家自己是怎么说的:

James Gosling on Java, May 1999

Bill Venners:In Java you included multiple inheritance of interface, but left out multiple inheritance of implementation. Were you trying to say anything to designers by making the interface a separate construct? Were you trying to say anything by leaving out multiple inheritance of implementation? How did that come about?

James Gosling: It listened to people from the C++ and Objective-C camps, and I tried to sort out who had the most happy experiences. The Objective-C notion of a pure interface with no implementation seemed to have worked out really well for people. It avoids a lot of the sticky issues such as disambiguation that people get into in C++. It's still kind of messy. It's an area that I don't feel totally happy with.

Bill Venners: In what way?

James Gosling: Another way for doing these things is a technique called delegation. Some ideas in the delegation camp felt good, but I never came up with anything that really worked. I ended up with the interface construct, which felt simple enough to be comprehensible, sophisticated enough to be useful. It also avoided any of the tar pits that the other folks got into.

纯粹是高司令老人家的taste。

然后,从Java 8开始,接口允许为方法提供“默认实现”了——默认方法(default method)。因而实质上Java 8的接口多继承其实也会涉及到实现多继承,并且语言层面有专门规定去解决实现多继承时选择哪个版本的问题——哪个都不选择,而是在发现会继承多个默认方法实现并且没有override时报错,逼使用户显式override可能冲突的方法。

这使得Java 8开始接口可以当作traits来使用,达到实现多继承的目的。

 

Java 8语言规范的一些相关新规定:

8.4.8. Inheritance, Overriding, and Hiding

9.4. Method Declarations

13.5.6. Interface Method Declarations

以上就是IT培训网java编程培训班给大家做的内容详解,更多关于java的学习,请继续关注IT培训网官网。更多精彩等你来看。

全国1000多家名企招聘

500家企业人才定制培养需求

想不就业,太难!

IT培训就业之一 IT培训就业之二 IT培训就业之三
学员最关心的就业问题
想学员之所想,解学员之所惑
我怎么样选择
合适的IT课程?

我怎么样选择合适的IT课程?-Java不支持多继承,这是个BUG?

学了IT课程后
能保证就业吗?

学了IT课程后能保证就业吗?-Java不支持多继承,这是个BUG?

学了IT后可以进
哪些企业?

学了IT后可以进哪些企业?-Java不支持多继承,这是个BUG?

0基础
学什么专业更好?

0基础学什么专业更好?-Java不支持多继承,这是个BUG?

IT培训网课程的
优势有哪些?

IT培训网课程的优势有哪些?-Java不支持多继承,这是个BUG?

IT课程学费多少钱?

IT课程费多少钱?-Java不支持多继承,这是个BUG?

版权所有:IT培训网 备案信息:中国优质IT培训网

课程免费咨询热线:13783581536