Java – why does erasure complicate the implementation of function types?

I read from interview with Neal gafter:

Editor: another place where similar statements are encountered is Brian Goetz's message in lambda dev mailing list, where he said that when they are only anonymous grammatical sugars, they are easier to deal with:

Can anyone explain these statements? Why do I need runtime type information for Lambdas?

Solution

The way I understand is that they decide that due to erasure, it will be a messy "function type" way, such as the representation in c# and they can only use lambda expressions, which is just a simple single abstract method class syntax

Representative in C #:

public delegate void DoSomethingDelegate(Object param1,Object param2);
...
//Now assign some method to the function type variable (delegate)
DoSomethingDelegate f = DoSomething;
f(new Object(),new Object());

(another sample is here http://geekswithblogs.net/joycsharp/archive/2008/02/15/simple-c-delegate-sample.aspx )

An argument they put forward in the project lambda document:

Section 2: http://cr.openjdk.java.net/ ~briangoetz/lambda/lambda-state-3. html

(the syntax of the final lambda expression will be somewhat different from the above documents: http://mail.openjdk.java.net/pipermail/lambda-dev/2011-September/003936.html )

(x,y) => { System.out.printf("%d + %d = %d%n",x,y,x+y); }

In a word, my best understanding is that only some grammatical things can be used in practice Neal gafter most likely means that the inability to use delegates will make it more difficult for the standard API to adapt to the functional style than to complete javac / JVM updates

If someone knows better than me, I'll be glad to see his account

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>