1

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:

  • Deleting and re-writing the class
  • downgrading java version inside intellijIDEA
  • re-installing the whole IDE
  • asking chatty, what to do. The AI just suggests to make some changes in the settings and ignore error-messages. Wasn't helpful, either.
  • couldn't find a similar issue elsewhere on the web.
2
  • You erroneously activated a future java version's preview feature.. You can look at this - Project Structure / Preview. Maybe start in a new pristine directory and copy the sources. Commented Apr 10 at 11:57
  • Thank you Joop, I had tried that with no change. Cheers! Marit's path solved the problem. :) Cheers and thanks for helping. Commented Apr 10 at 19:08

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much Marit. Doing both of the steps you described solved the problem. I renamed the "parent" version of the class and in refactor I could move the "child"-version a level up. and delete the "parent". Now I could fill in my getter-methods and it's working fine. Thanks again! Cheers!
@elAndres You're welcome, and good luck learning Java.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.