C#重载分辨率? [英] C# overloading resolution?

查看:180
本文介绍了C#重载分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文章安德斯Hejsberg采访,我们所做的重载在C#分辨率的方法是从任何其他不同语言
有人可以提供C#和Java的例子吗?

From the article Anders Hejsberg interview, "the way we do overload resolution in C# is different from any other language" Can somebody provide some examples with C# and Java?

推荐答案

什么安德斯渐渐在这里是原来的设计团队明确地设计了重载解析算法有一个很好的工作的某些属性与版本的场景,即使是当你考虑的方案,而不会版本这些属性似乎倒退或混淆。

What Anders was getting at here was that the original design team explicitly designed the overload resolution algorithm to have certain properties that worked nicely with versioning scenarios, even though those properties seem backwards or confusing when you consider the scenarios without versioning.

大概是最常见的例子是在C#中的规则,如果有的话在更派生类的方法是适用的候选者,它会自动比任何更好的方法在派生类较少,即使衍生少方法具有较高的签名匹配的。这个规则是不是,据我所知,在有重载其它语言中。这似乎有悖常理;如果有这是一个更好的特征码匹配的方法,为什么不选择它呢?究其原因是因为的可能已经在以后的版本的,从而推出一个脆基类失败。

Probably the most common example of that is the rule in C# that if any method on a more-derived class is an applicable candidate, it is automatically better than any method on a less-derived class, even if the less-derived method has a better signature match. This rule is not, to my knowledge, found in other languages that have overload resolution. It seems counterintuitive; if there's a method that is a better signature match, why not choose it? The reason is because the method that is a better signature match might have been added in a later version and thereby be introducing a "brittle base class" failure.

有关如何各种语言处理脆基类的失败更多的心思,见

For more thoughts on how various languages handle brittle base class failures, see

http://blogs.msdn.com/b/ericlippert/archive/tags/brittle+base+classes/

和对重载更多的心思,见

and for more thoughts on overload resolution, see

http://blogs.msdn.com/b/ericlippert/archive/tags/overload+resolution/

这篇关于C#重载分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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