flink apply 方法中为什么不能使用 lambda?

问答 shishuai19910217 ⋅ 于 2019-03-09 00:40:57 ⋅ 最后回复由 青牛 2019-03-11 08:40:09 ⋅ 3978 阅读

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有什么限制吗?
成为第一个点赞的人吧 :bowtie:
回复数量: 1
  • 青牛 国内首批大数据从业者,就职于金山,担任大数据团队核心研发工程师
    2019-03-11 08:40:09

    不是语法的问题吧 编辑器的问题吧 Eclipse的bug 换一个编辑器

暂无评论~~
  • 请注意单词拼写,以及中英文排版,参考此页
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
  • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
  • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
  • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
Ctrl+Enter