Why can't javac access List, given that List is part of the JRL

Viewed 57

I'm trying to compile a Spring Boot tutorial, but am getting an error.

[ERROR] /Users/jimstockwell/Birds/application/src/main/java/com/okta/developer/BirdController.java:[23,35] cannot access List
  class file for List not found

I'm using Maven, and a very sparse pom file. (I've tried javac directly too.)

I'll post more information as question develop in the comments, since posting the whole project seems excessive. :)

The apparently offending code is:

package com.okta.developer;

import com.okta.developer.animals.bird.Bird;
import com.okta.developer.animals.bird.BirdPersistence;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BirdController {

    private BirdPersistence birdPersistence;

    public BirdController(BirdPersistence birdPersistence) {
        this.birdPersistence = birdPersistence;
    }

    @GetMapping("bird")
    public List<Bird> getBird() {
        return birdPersistence.get();
    }

    @PostMapping("bird")
    public void saveBird(@RequestBody Bird bird) {
        birdPersistence.save(bird);
    }
}

(and line 23 is the one that reads: return birdPersistence.get();)

I don't understand what's going on. Since List is part of lang.util, how can the compiler say "cannot access List"?

Can anyone give some insight? Thanks in advance.

Edit: If I change getBird as follows (and add ArrayList to imports), it compiles fine:

    public List<Bird> getBird() {
        return new ArrayList<Bird>();
/*        return birdPersistence.get(); */
    }
0 Answers
Related