箭头操作符如何在java 8中内部工作? [英] How does the arrow operator work internally in java 8?

查看:370
本文介绍了箭头操作符如何在java 8中内部工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道箭头的左侧有参数,箭头的右侧是参数所在的函数。但是,我想知道java 8如何映射左侧和右侧并转换为函数。那里发生了什么,我在哪里可以找到这些信息?

I understand that left side of the arrow has the arguments and right side of the arrow is the function where the arguments go to. But, I would like to know how does java 8 map the left side and right side and convert into a Function. What happens there and where can I find the information?

推荐答案

当你有一个 - > javac编译器添加一个静态方法和代码的内容。它还向类添加动态调用方信息,以便JVM可以将lambda实现的接口映射到参数和返回类型。 JVM在运行时生成代码以将接口绑定到生成的方法。

When you have an -> the javac compiler adds a static method with the contents of the code. It also adds dynamic call side information to the class so the JVM can map the interface the lambda implements to the arguments and return type. The JVM generates code at runtime to bind the interface to the generated method.

与lambdas和匿名类的区别在于隐含变量只需要有效最终(如可能已经成为最终的)并且复制了成员变量,即它没有保留对外部类的 this 的引用。

A difference with lambdas and anonymous classes is that implict variables only need to be effectively final (as in could have been made final) and member variables are copied i.e. it doesn't keep a reference to the this of an outer class.

它可以区分 Runnable Callable< void> ,即使两者都没有参数。有关详细信息,请 http://vanillajava.blogspot.com/2014/ 09 / lambdas-and-side-effects.html

It can tell the difference between Runnable and Callable<void> even though both take no arguments. For more details http://vanillajava.blogspot.com/2014/09/lambdas-and-side-effects.html

这篇关于箭头操作符如何在java 8中内部工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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