-2

I've read What is the difference between List.of and Arrays.asList?

What I'm not getting is why, after some dependency upgrades in my Maven pom.xml, suddenly all my

List.of(FLIGHT1_SPEND_AGG, FLIGHT1_IMPRESSIONS_AGG)

no longer compile. When I type List. in IntelliJ, autocomplete only comes up with the class member. I thought maybe I'm not importing java.util.List? So explicitly specified it, but still:

enter image description here

I'm using Java 11, and I see the method exists here: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html.

Why can't I seem to use it? I must be doing something stupid...

Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
  • Oh, is it because `long` is mutable? But then... how did it compile before? (What change in dependency could have flipped that?) – Andrew Cheong Dec 02 '19 at 13:02
  • 4
    Probably because your pom doesn't specify Java 11, and when you reimported for the upgrades it reset the language level in IntelliJ. – OrangeDog Dec 02 '19 at 13:07
  • Sometimes IntelliJ causes issues and couldn't find the functions even though the libraries are in the class-path. Maybe try restarting the IDE or clear the IDE cache? – ihaider Dec 02 '19 at 13:21
  • @StopHarmingMonica - That was exactly it. If you'd like to add your answer as an answer, I can accept yours. – Andrew Cheong Dec 02 '19 at 13:39

1 Answers1

2

It looks like you defined your Java version in your ide but not in your pom (at least not correctly)

Your pom needs to specify the maven-compiler-plugin and the source and target java versions.

The definition should look similar to this one:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>11</source>
        <target>11</target>
    </configuration>
</plugin>

After the updates from maven, your IDE is using the Java version defined in your pom or using the default (which for some versions of the compiler plugin is as old as Java 5), overriding whatever you've set before.

Nicktar
  • 5,548
  • 1
  • 28
  • 43