1

我在这里遵循了 tut http://sparkjava.com/documentation.html#getting-started

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>spark</groupId>
  <artifactId>Spark</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>spark</name>
  <description>spark</description>  
  <dependencies>
      <dependency>
        <groupId>com.sparkjava</groupId>
        <artifactId>spark-core</artifactId>
        <version>2.2</version>
    </dependency>

  </dependencies>
</project>

你好.java

import static spark.Spark.*;

    public class Hello {
        public static void main(String[] args) {
            get("/hello", (req, res)-> "Hello World");//eclipse error this line
        }
    }

eclipse出错了

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    req cannot be resolved to a variable
    Syntax error on token ",", . expected
    Syntax error on token "-", -- expected

    at Hello.main(Hello.java:5)
4

1 回答 1

4

Java 的 lambda 表达式是 Java 8 中的一个特性:Oracle 链接。您需要将合规级别(以及 java 版本和 pom)更改为 java 8 才能编译此示例。

于 2015-07-13T08:04:48.750 回答