Flink 报错:The generic type parameters of 'Tuple2' are missing. In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved

针对flink中的算子为什么要返回指定的类型,不然的话报错比如(Tuple,KeyBy)

函数的输入i和输出参数的类型map()无需声明,因为它们是Java编译器推断的。有的则使Flink无法自动推断输出类型的类型信息。

常见报错信息:

org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Collector' are missing.
    In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved.
    An easy workaround is to use an (anonymous) class instead that implements the 'org.apache.flink.api.common.functions.FlatMapFunction' interface.
    Otherwise the type has to be specified explicitly using type information.

参考官网:

https://ci.apache.org/projects/flink/flink-docs-stable/dev/java_lambdas.html