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

基本上,.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

为什么C#不使用多继承?(from stackoverflow)的更多相关文章

  1. C++ 系列:继承

    Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

  2. Stackoverflow/dapper的Dapper-Extensions用法(二)

    之前翻译了Dapper-Extensions项目首页的readme.md,大家应该对这个类库的使用有一些了解了吧,接下来是wiki的文档翻译,主要提到了AutoClassMapper.KeyTypes ...

  3. Stackoverflow/dapper的Dapper-Extensions用法(一)

    Dapper-Extensions Dapper Extensions is a small library that complements Dapper by adding basic CRUD ...

  4. 深入浅出JS的封装与继承

    JS虽然是一个面向对象的语言,但是不是典型的面向对象语言.Java/C++的面向对象是object - class的关系,而JS是object - object的关系,中间通过原型prototype连 ...

  5. Java中的继承与组合(转载)

    本文主要说明Java中继承与组合的概念,以及它们之间的联系与区别.首先文章会给出一小段代码示例,用于展示到底什么是继承.然后演示如何通过“组合”来改进这种继承的设计机制.最后总结这两者的应用场景,即到 ...

  6. 关于opacity透明度子元素继承现象的若干研究以及hack方法

    [感想]信息时代的信息是有时效性的,今天是确确实实感受到了.互联网资料虽然丰富,但是质量不一,还有大量的跟风雷同,很多人都是随手拷贝过来,根本没有实践.以前端为例,这两年浏览器的迅猛发展,造成很多原有 ...

  7. Inheritance, Association, Aggregation, and Composition 类的继承,关联,聚合和组合的区别

    在C++中,类与类之间的关系大概有四种,分别为继承,关联,聚合,和组合.其中继承我们大家应该都比较熟悉,因为是C++的三大特性继承Inheritance,封装Encapsulation,和多态Poly ...

  8. StackOverflow:7个你从未见过的Java问题最佳答案

    本文由码农网 – 李俊英原创翻译,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 对开发人员来说, StackOverflow就像一个金矿.对具体的问题,它能帮我们找到最有用的答案,并且我们也 ...

  9. 继承BaseAdapter实现Filterable的adapter类完整示例

    转载:http://www.lai18.com/content/1631130.html 目标:自定义ListView项布局通常需要自己实现Adapter,并通过搜索关键字筛选部分数据.且关键字变长变 ...

随机推荐

  1. MVC4 使用概述

    1.Bundle使用: http://www.cnblogs.com/inline/p/3897256.html 2.MVC总结: http://www.cnblogs.com/xlhblogs/ar ...

  2. 无废话ExtJs 入门教程十五[员工信息表Demo:AddUser]

    无废话ExtJs 入门教程十五[员工信息表Demo:AddUser] extjs技术交流,欢迎加群(201926085) 前面我们共介绍过10种表单组件,这些组件是我们在开发过程中最经常用到的,所以一 ...

  3. SQL SERVER 索引之聚集索引和非聚集索引的描述

    索引是与表或视图关联的磁盘上结构,可以加快从表或视图中检索行的速度. 索引包含由表或视图中的一列或多列生成的键. 这些键存储在一个结构(B 树)中,使 SQL Server 可以快速有效地查找与键值关 ...

  4. PHP二维数组去除重复,重复值相加

    $arr = array( array('id' => 122, 'name' => '张三', 'amount' => '1'), array('id' => 123, 'n ...

  5. QQ的账号登录及api操作

    .qq.php <?php /** * PHP Library for qq.com * * @author */ class qqPHP { function __construct($app ...

  6. [SQL]查询及删除重复记录的SQL语句

    一:查询及删除重复记录的SQL语句1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select ...

  7. bbed的使用--查看数据文件信息 & sid信息

    1.得到文件的块大小和数据块个数 在Linux和Unix上,oracle提供了一个小工具dbfsize用于查看文件块大小 (可以参看[ID:360032.1]How to detect and fix ...

  8. LoadRunner IP欺骗(转)

    直接转了篇运用LR来实现IP欺骗的文章. http://www.cnblogs.com/fnng/archive/2013/03/02/2940284.html

  9. LoadRunner11录制APP脚本(1)

    1.测试准备: a.首先安装LoadRunner11.0的版本跟新

  10. Java会出现"unreachable code"错误的几个例子

    public class exam { static int num=5; static int m1(){ try{ num=6; throw new NullPointerException(); ...