Java 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.

    This document shows how to use lambda expressions and describes current limitations. For a general introduction to theFlink API, please refer to the Programming Guide

    Flink can automatically extract the result type information from the implementation of the method signature OUT map(IN value) because is not generic but Integer.

    Unfortunately, functions such as flatMap() with a signature void flatMap(IN value, Collector<OUT> out) are compiled into by the Java compiler. This makes it impossible for Flink to infer the type information for the output type automatically.

    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.

    Similar problems occur when using a map() function with a generic return type. A method signature Tuple2<Integer, Integer> map(Integer value) is erasured to in the example below.