StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//连接socket获取输入的数据
DataStreamSource<String> text = env.socketTextStream("127.0.0.1", 4700);
text.map(action->{
return action;
}).timeWindowAll(Time.seconds(5))
.apply(new AllWindowFunction<String, Iterable<String>, TimeWindow>() {
public void apply(TimeWindow window, Iterable<String> values, Collector<Iterable<String>> out) throws Exception {
out.collect(values);
}
}).print();
env.execute("streaming word count");
以上的代码是正确的可以执行的
但是将apply方法中匿名类换成lambda 就出问题了
如下:
//获取运行环境
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//连接socket获取输入的数据
DataStreamSource<String> text = env.socketTextStream("127.0.0.1", 4700);
text.map(action->{
return action;
}).timeWindowAll(Time.seconds(5))
.apply((a,b,c)->{}).print(); 这样改成lambda 就报错了
env.execute("streaming word count");
会报以下错误:
org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Iterable' are missing.
It seems that your compiler has not stored them into the .class file.
Currently, only the Eclipse JDT compiler preserves the type information necessary to use the lambdas feature type-safely.
See the documentation for more information about how to compile jobs containing lambda expressions.
为什么 ? lambda有什么限制吗?