简体   繁体   English

无法将println解析为变量

[英]println cannot be resolved as a variable

I am studying object oriented programming in my university and my professors is making an example of streams on java. 我正在大学学习面向对象的编程,我的教授们正在用Java编写流的示例。 Unfortunately when I try to run this code it says "println cannot be resolved as a variable" on System.out::println . 不幸的是,当我尝试运行此代码时,在System.out::println上显示“无法将println解析为变量”。 It also says to delete the two colons, while on my professor's eclipse it does work. 它还说删除两个冒号,而在我的教授的月食上确实起作用。

This is the code. 这是代码。 I am running it on eclipse for ubuntu and my version of java is 1.8 update 91 我正在eclipse上为ubuntu运行它,而我的Java版本是1.8更新91

package stream;

import java.util.Arrays;

public class StreamExamples {

    public static void main(String[] args){
        String text = "I have no idea what is the problem";
        String[] words = text.split(" ");

        Arrays.stream(words)        
        .sorted()
        .limit(3)
        .forEach(System.out::println);
    }
}

Most likely the version of Eclipse you are running does not understand Java 8 syntax. 您正在运行的Eclipse版本很可能不了解Java 8语法。

You need to be running the current Eclipse 4.6 (Neon) or the previous release 4.5 (Mars) for full Java 8 support. 您需要运行当前的Eclipse 4.6(Neon)或先前的版本4.5(Mars),以全面支持Java 8。 You code works fine on Eclipse Neon. 您的代码在Eclipse Neon上运行良好。

1) Check your build path by right clicking on your project, Build Path > Configure Build Path . 1)通过右键单击您的项目Build Path> Configure Build Path来检查您的构建路径 The libraries tab should show a JRE with version 1.8, if that is not the case, click Edit and select a JRE that is at least version 8. 库选项卡应显示版本为1.8的JRE,如果不是,请单击“ 编辑”并选择至少版本为8的JRE。

2) Check the compiler settings by right clicking on your project, Properties > Java Compiler . 2)右键单击项目,然后单击属性> Java编译器 ,检查编译器设置。 Change the Compiler compliance level to 1.8. 编译器合规性级别更改为1.8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM