java Lambda expressions are not supported at this language level

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33939333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:19:17  来源:igfitidea点击:

Lambda expressions are not supported at this language level

javaintellij-ideaapache-spark

提问by Klausos Klausos

I have a Java class that uses Spark. I need to filter out the header from JavaRDD. This is how I want to do this.

I have a Java class that uses Spark. I need to filter out the header from JavaRDD. This is how I want to do this.

String first = data.first();
JavaRDD<String> filteredData = data.filter((String s) -> {return !s.contains(first);});

However, this code data.filter((String s) -> {return !s.contains(first);})cannot be compiled. IntelliJ IDE says "Lambda expressions are not supported at this language level".

However, this code data.filter((String s) -> {return !s.contains(first);})cannot be compiled. IntelliJ IDE says "Lambda expressions are not supported at this language level".

回答by pepyakin

You can use lambdas on Java 7, but it is a bit involved —?you have to use something like Retrolambda.

You can use lambdas on Java 7, but it is a bit involved —?you have to use something like Retrolambda.

Also you can do the same thing without lambdas. Lambdas can be easily represented via annonymous classes, however it is a lot more verbose.

Also you can do the same thing without lambdas. Lambdas can be easily represented via annonymous classes, however it is a lot more verbose.

final String first = data.first();
JavaRDD<String> filteredData = data.filter(new Function<String, Boolean>() {
  @Override public Boolean call(String s) {
    return !s.contains(first);
  }
});