未验证 提交 6e8d9c41 编写于 作者: 片刻小哥哥's avatar 片刻小哥哥 提交者: GitHub

Merge pull request #46 from apachecn/feature/flink_1.7_doc_zh_14

14 完成
......@@ -2,15 +2,15 @@
# Java Lambda Expressions
Java 8 introduced several new language features designed for faster and clearer coding. With the most important feature, the so-called “Lambda Expressions”, it opened the door to functional programming. Lambda expressions allow for implementing and passing functions in a straightforward way without having to declare additional (anonymous) classes.
Java 8引入了几个新的语言特性,旨在实现更快、更清晰的编码。最重要的特性,即所谓的“Lambda表达式”,为函数式编程打开了大门。Lambda表达式允许以简单的方式实现和传递函数,而不必声明其他(匿名)类。
Attention Flink supports the usage of lambda expressions for all operators of the Java API, however, whenever a lambda expression uses Java generics you need to declare type information _explicitly_.
注意Flink支持JavaAPI的所有操作符使用lambda表达式,但是,每当lambda表达式使用Java泛型时,都需要声明信息类型 _explicitly_。
This document shows how to use lambda expressions and describes current limitations. For a general introduction to the Flink API, please refer to the [Programming Guide](//ci.apache.org/projects/flink/flink-docs-release-1.7/dev/api_concepts.html)
本文档演示如何使用lambda表达式,并描述当前的限制。有关FLinkAPI的一般介绍,请参阅[编程Guide](//ci.apache.org/projects/flink/flink-docs-release-1.7/dev/api_concepts.html)]
### Examples and Limitations
### Examples and Limitations (实施例和限制)
The following example illustrates how to implement a simple, inline `map()` function that squares its input using a lambda expression. The types of input `i` and output parameters of the `map()` function need not to be declared as they are inferred by the Java compiler.
下面的示例说明了如何实现一个简单的内联`map()`函数,该函数使用lambda表达式对其输入进行平方。不需要声明`map()`函数的输入 `i` 和输出参数的类型,因为它们是由Java编译器推断的。
......@@ -23,11 +23,11 @@ env.fromElements(1, 2, 3)
Flink can automatically extract the result type information from the implementation of the method signature `OUT map(IN value)` because `OUT` is not generic but `Integer`.
Flink可以从方法签名`OUT map(IN value)`的实现中自动提取结果类型信息,因为`OUT` 不是通用的,而是`Integer`
Unfortunately, functions such as `flatMap()` with a signature `void flatMap(IN value, Collector<OUT> out)` are compiled into `void flatMap(IN value, Collector out)` by the Java compiler. This makes it impossible for Flink to infer the type information for the output type automatically.
不幸的是,由Java编译器将诸如`flatMap()`和签名`void flatMap(IN value, Collector<OUT> out)` 之类的函数编译为`void flatMap(IN value, Collector out)`。这使得Flink无法自动推断输出类型的类型信息。
Flink will most likely throw an exception similar to the following:
FLink最可能抛出类似以下内容的异常:
......@@ -40,7 +40,7 @@ org.apache.flink.api.common.functions.InvalidTypesException: The generic type pa
In this case, the type information needs to be _specified explicitly_, otherwise the output will be treated as type `Object` which leads to unefficient serialization.
在这种情况下,需要_显式地指定_类型信息,否则输出将被视为`Object`类型,这将导致无效的序列化。
......@@ -67,7 +67,7 @@ input.flatMap((Integer number, Collector<String> out) -> {
Similar problems occur when using a `map()` function with a generic return type. A method signature `Tuple2&lt;Integer, Integer&gt; map(Integer value)` is erasured to `Tuple2 map(Integer value)` in the example below.
在使用带有泛型返回类型的`map()`函数时,也会出现类似的问题。在下面的示例中,将一个方法签名`Tuple2&lt;Integer, Integer&gt; map(Integer value)` 删除为 `Tuple2 map(Integer value)`
......@@ -82,7 +82,7 @@ env.fromElements(1, 2, 3)
In general, those problems can be solved in multiple ways:
一般来说,这些问题可以通过多种方式解决:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册