Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

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");
    }
}

like image 330
M.Gumede Avatar asked Dec 17 '22 17:12

M.Gumede


1 Answers

The overloaded List.of methods were introduced in Java 9.

Since:
9

You must be compiling with an older version. Update to Java 9 or later. Here's how.

like image 129
Savior Avatar answered Mar 15 '23 23:03

Savior