为什么不.NET风格的代表,而不是关闭在Java中? [英] Why not .NET-style delegates rather than closures in Java?

查看:183
本文介绍了为什么不.NET风格的代表,而不是关闭在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定,这将是我的跳动一个垂死的马第3次。

OK, this is going to be my beating a dying horse for the 3rd time.

不过,这个问题是从我前面2闭包/代表,它询问计划代表不同的,什么是预计的规格和实施封锁。

However, this question is different from my earlier two about closures/delegates, which asks about plans for delegates and what are the projected specs and implementation for closures.

这个问题是关于 - 为什么Java社区奋力定义3个不同类型的闭包的时候,我们可以简单地偷了整个概念的代表锁,股票和桶从我们心爱的和友好的邻邦 - 微软

This question is about - why is the Java community struggling to define 3 different types of closures when we could simply steal the whole concept of delegates lock, stock and barrel from our beloved and friendly neighbour - Microsoft.

有两个非技术性的结论,我会非常希望直接进入:

There are two non-technical conclusions I would be very tempted to jump into:

  1. 在Java社区应该托起它的骄傲,在需要或去救援人员到场费解的努力,通过不屈服于任何借用微软的概念,否则平反微软的辉煌的成本。
  2. 代表是微软的专利技术。

好了,除了上述两种可能性,

Alright, besides the above two possibilities,

Q1。是否有.NET风格的代表任何弱点或不足之处,这三个(或更多)的形式倒闭将被处理?

Q1. Is there any weakness or inadequacy in .NET-style delegates that the three (or more) forms of closures would be addressing?

Q2。我问这个,而Java和C#之间转换,这令我着迷的C#代表不正是我需要的。是否有功能,将被封在当前未在C#代表可用执行?如果是这样它们是什么,因为我看不到什么,我需要比什么C#代表已经充分提供给我?

Q2. I am asking this while shifting between Java and C# and it intrigues me that C# delegates does exactly what I needed. Are there features that would be implemented in closures that are not currently available in C# delegates? If so what are they because I cannot see what I need more than what C# delegates has adequately provided me?

Q3。我知道,对实施关闭/代表在java中关注的问题之一是语言,一个以上的方式暴露在执行特定任务的正交性的降低。它是值得的水平卷积,花了避免代表只是为了确保Java的保留正交性的水平时间?在关系设计中,我们知道,最好是通过经常适当地,仅满足第二范式突破正交性。为什么不是Java进行还原正交性和面向对象的烦躁,为简单起见?

Q3. I know that one of the concerns about implementing closures/delegates in java is the reduction of orthogonality of the language, where more than one way is exposed to perform a particular task. Is it worth the level convolution and time spent to avoid delegates just to ensure java retains its level of orthogonality? In relational design, we know that it is advisable to break orthogonality by frequently adequately satisfying only the 2nd normal form. Why can't java be subjected to reduction of orthogonality and OO-ness for the sake of simplicity?

Q4。 JVM的体系结构从技术上实现.NET风格的代表约束。如果这个原因是:(虚拟语气强调祈)属实,那么为什么不能三封提案被隐藏在一个简单的委托关键字或注解:如果我们不喜欢用@Delegate,我们可以使用@method。我看不出委托声明格式比三封提案更加复杂。

Q4. The architecture of JVM is technically constrained from implementing .NET-styled delegates. If this reason WERE (subjunctive to emphasize unlikelihood) true, then why can't the three closures proposals be hidden behind a simple delegate keyword or annotation: if we don't like to use @delegate, we could use @method. I cannot see how delegate statement format is more complex than the three closure proposals.

推荐答案

您的问题是讽刺。你想知道为什么Java社区正在努力与三个不同的建议,将封闭,而你所建议的解决方案是第四个选项加进来?

Your question is ironic. You're wondering why the Java community is struggling with three different proposals for adding closures, and your suggested solution is to add a fourth option to the mix?

但是,为了回答你的问题:

But to answer your question:

  • 正确的论坛,讨论的OpenJDK项目的lambda邮件列表。这不是一个地方的建议可能会影响这一努力。

  • The right forum for discussion is the mailing list of openjdk project lambda. This is not a place where suggestions are likely to influence that effort.

类型系统C#和Java是显著不同,所以C#的解决方案将不直接适用。例如,C#有报关现场方差(输入/输出),而Java有使用现场方差(通配符)。拉姆达参数类型推断的规定在C#也不会在Java中使用。

The type systems for C# and Java are significantly different, so the C# solution would not directly apply. For example, C# has declaration-site variance (in/out), while java has use-site variance (wildcards). Inference of lambda parameter types as specified in C# would not apply in Java.

Java的的发展必须保持向下兼容,但增加了委托关键字将是一个重大更改。

The evolution of Java must remain backward compatible, but adding the delegate keyword would be a breaking change.

C#有三种类型的代表EX pressions:旧与委托关键字,lambda表达式用=> {,和前pression lambda表达式。如果C#语言的团队有它做一遍,我们就肯定不会有这么多的形式。为什么要采用Java的C#的历史包袱?

C# has three types of delegate expressions: the old one with the delegate keyword, statement lambdas with =>{, and expression lambdas. If the C# language team has it to do over again, we'd certainly not have this many forms. Why should Java adopt C#'s historical baggage?

由于C#泛型工作在原语中,func<>和行动<>委托类型,可以为使用不佳人的构造函数类型。但在Java中,仿制药被删除,工作仅在引用类型和类型不能由自己的元数来区分。因此爪哇就必须有一个大的数目明显不同的名为标准的的功能类型来得到相同的效果。这不会是pretty的。

Because C# generics operate over primitives, the Func<> and Action<> delegate types can be used as poor-man's structural function types. But in Java, generics are erased, work only over reference types, and types cannot be distinguished by their arity. Consequently Java would have to have a large number of distinctly-named "standard" function types to get the same effect. That would not be pretty.

总的来说,C#的解决方案并不适应Java的一个很自然的解决方案。

Overall, the C# solution does not adapt to a very natural solution in Java.

这篇关于为什么不.NET风格的代表,而不是关闭在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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