简体   繁体   English

无法解析方法“ List.of(java.lang.String,java.lang.String)”

[英]Cannot resolve method 'List.of(java.lang.String, java.lang.String)'

I've been trying to create a simple hello world application with Java and SpringBoot in IntelliJ IDEA, but I get this error and I don't know how to solve it. 我一直试图在IntelliJ IDEA中使用Java和SpringBoot创建一个简单的hello world应用程序,但是出现此错误,我不知道如何解决。

I get the error at the return. 我在返回错误。 Java doesn't seem to know how to resolve the of method that's in the public List<String> getHelloWorld method. Java的似乎不知道如何解决of方法,这就是在public List<String> getHelloWorld方法。

package com.myname.SpringApp;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;


@RestController
public class HelloWorldController {
    @RequestMapping("api/hello-world")
    @GetMapping
    public List<String> getHelloWorld(){
        return List.of("Hello", "World");
    }
}

The overloaded List.of methods were introduced in Java 9. Java 9中引入了重载的List.of方法

Since: 以来:
9 9

You must be compiling with an older version. 您必须使用旧版本进行编译。 Update to Java 9 or later. 更新到Java 9或更高版本。 Here's how. 这是如何做。

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

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