classintellij-ideafinalimplicit-declaration

Implicitly declared classes in IntellijIDEA - how to deactivate that feature


First of all, I am a beginner in programming, so please don't expect me to now a lot about this.

I am working on a project for my programming course in computer science, where we use JUnit for tests provided by the professor.

As I was trying to solve a problem, the IDE asked if, I'd like to change to a preview version of Java. By doing so, implicitly declared classes were introduced. We are building an OOP project, so there are some files only containing classes, constructors instance methods as well as getter and setter for said objects. But no main-classes.

Now a specific class is divided and wrapped together somehow. All getters end up in a "parent"-class of the same name, while the rest (objects, their constructors, methods and setter) are in a file "wrappped" in the first. I describe it like that, because it is visible in the tree hierarchy on the left.

| |_ CustomerVO.java (final class) | |_CustomerVO.java

The parent one has a mouseover-message signaling it would be "final class" although, I never declared it as such.

Furthermore running the code results in this reacuring error-message: "Implicitly declared classes are not supported at language level '23'"

Well, duh. I don't want them to be supported. And I've never declared a class implicit. I don't even know exactly, what that means.

I changed the Java version in the Settings, deleted the file and redid it. Still. As soon, as it contains the getter methods, I am back in this weird situation.

What can I do?

All I tried all the before mentioned solutions trials:


Solution

  • To convert your implicit class back into a regular class:

    1. Click Alt+Enter on void main() in your file.

    2. Select "Convert implicitly declared class into regular class".

    To set the project back to a release version of Java, without preview features:

    1. Open the Project Structure (From the menu, go to File | Project Structure).

    2. Under Project Settings | Project, set field SDK to the SDK you want to use (I'm assuming Java 21 - 24), and set Language Level to "SDK default".

    3. Just to make sure, go to Project Settings | Modules and set Language Level to "Project default" here.