简单地说:是因为该语言的设计者决定不使用。

基本上,.NET和Java的设计者不使用多继承(MI),是因为他们认为给语言加上多继承获得的好处较少抵不上因此增加的复杂性

1、不同的语言对于多继承如何工作实际上有不同的期望。比如说,在冲突时基类如何合并或处理冗余。在CLR中实现多继承之前,我们需要查看一下所有其他的语言,看看一些共通的概念,并在一种语言-中立的方式来表示它们。我们还需要决定多继承是否应存在   于CLS,而这对于不想要这个概念的语言(比如说可能有VB.NET)。当然,这本是公共语言运行时的分内之事,然而我们没有找到足够的时间为此来做。

2、多继承真正合适的地方实际上很少。在很多情况下,多接口实现都可以做这个事。在其他情况下,你可以使用封装和委托。假如我们添加一个稍微不同的构造器,如mixins,会更强大吗?

3、多继承给实现增加了很多的复杂性。这个复杂性影响了类型转换,布局,字段访问,序列化,身份比较,可验证,反射,泛型以及可能还有很多别的地方。

原文:

The short answer is: because the language designers decided not to.

Basically, it seemed that both the .NET and Java designers did not allow multiple inheritance because they reasoned that adding MI added too much complexity to the languages while providing too little benefit.

  1. Different languages actually have different expectations for how MI works. For example, how conflicts are resolved and whether duplicate bases are merged or redundant. Before we can implement MI in the CLR, we have to do a survey of all the languages, figure out the common concepts, and decide how to express them in a language-neutral manner. We would also have to decide whether MI belongs in the CLS and what this would mean for languages that don't want this concept (presumably VB.NET, for example). Of course, that's the business we are in as a common language runtime, but we haven't got around to doing it for MI yet.

  2. The number of places where MI is truly appropriate is actually quite small. In many cases, multiple interface inheritance can get the job done instead. In other cases, you may be able to use encapsulation and delegation. If we were to add a slightly different construct, like mixins, would that actually be more powerful?

  3. Multiple implementation inheritance injects a lot of complexity into the implementation. This complexity impacts casting, layout, dispatch, field access, serialization, identity comparisons, verifiability, reflection, generics, and probably lots of other places.

引自:http://stackoverflow.com/questions/995255/why-is-multiple-inheritance-not-allowed-in-java-or-c

最新文章

  1. 【原】Github系列之二:开源 一行代码实现多形式多动画的推送小红点WZLBadge(iOS)
  2. sublime text3 前端编译神器,浏览器实时显示
  3. Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam
  4. 235. Lowest Common Ancestor of a Binary Search Tree
  5. openstack4j
  6. EF简单的增删查改
  7. mvc4 web-api 与unity搭建接口
  8. android开发之this.finish()的使用 分类: android 学习笔记 2015-07-18 19:05 30人阅读 评论(0) 收藏
  9. ubuntu 14.04 64位 下 编译安装MySQL 5.7.11
  10. Linux挂载U盘
  11. 三种方式实现观察者模式 及 Spring中的事件编程模型
  12. 2019-02-10 扩展Python控制台实现中文反馈信息
  13. Spark 实现wordcount
  14. sql进阶
  15. MySQL的log_bin和sql_log_bin 的区别
  16. QT中事件处理器和事件过滤器实现实例
  17. ELK之安装searchguard后默认管理员用户admin修改
  18. luogu2827 [NOIp2016]蚯蚓 (模拟)
  19. Java如何检查文件是否在服务器上被修改了?
  20. JS中如何生成全局变量

热门文章

  1. 【转载】Pyqt QSplitter分割窗口
  2. ASP.NET WebApi Document Helper
  3. WebRTC代码走读(八):代码目录结构
  4. (译)【Unity教程】使用Unity开发Windows Phone上的横版跑酷游戏
  5. win7-32 系统 + VS2010 配置 glew
  6. 【转】Struts2中json插件的使用
  7. Windows Server 2008 R2 实现多用户同时登陆
  8. hdu 2669 Romantic
  9. C# 溢出检查
  10. JavaScript 入门 (1)