#Why can't I use `var` anymore?

1 messages · Page 1 of 1 (latest)

wispy quail
#
import java.util.List;

public class Main {
    public static void main(String[] args) {
        var listOfColors = List.of("Red", "Blue", "Yellow"); // <- Here
        var dummyClass = new DummyClass(); // <- And here
        dummyClass.printColors(listOfColors);
    }
}

class DummyClass {
    void printColors(List<String> colors) {
        for (String color : colors) {
            System.out.println(color);
        }
    }
}
icy slateBOT
#

<@&987246399047479336> please have a look, thanks.

opal cobalt
#

what do u mean u cant use it?

#

using it there is valid java

wispy quail
#

Yeah, sorry, uploading those images took some time

#

That's what I mean though

#

So it says:

as of release 10, 'var' is a restricted type name and cannot be used for type declarations or as the element type of an array

Like, wat?

#

And I set my application to release 25 right

opal cobalt
#

try selecting "clean cache" or sth like that it was called. in the top left corner of intellij in the dropdown and restart intellij

wispy quail
#

Are there any checkboxes you want me to check or no?

#

Also, should I click on "Just restart" or "Invalidate and Restart"?

opal cobalt
#

check all and invalidate/restart

wispy quail
#

I mean, I can maybe change the language level down to something which works, but don't get what's wrong with 25

#

25 is where I get the latest features right?

#

That's what language level means?

#

Okay, I thought that post would work, but it still didn't..

azure orbit
#

Which version do you have set in your pom?

opal cobalt
#

u can also send us the Main.class file that u will find in that target folder

#

it will tell us in which java version it was compiled

#

that might help as well

#

but yeah, if its still using the wrong version its probably in the pom.xml file

autumn pasture
# wispy quail

click on modules and check what language level is set there

safe hemlock
#

just do ctrl alt shift s for intellije on windows, opens up the project structure, you can view the project structure and the language level

#

along with the jdk version

wispy quail
#

Oh shit, I forgot to update this thread

ornate heath
#

bro u mean when u used jdk 25
compile error of var not anymore used within jdk25 ?
because im using jdk21 i have no idea about 25 !

wispy quail