Julian_0920
Julian_0920

Reputation: 11

Encountering a Problem in IntelliJ which only accepts Wildcard Imports of java packages instead of specific Classes from java packages

Information about my Project:

My JAVA_HOME Path in the Windows environment variables is set to the newest Java JDK (15.0.2). The Project Language in the Project Structure Path is also set to Java 15.

I am currently using IntelliJ version 2020.3 and since a few days I have the following Problem. When I want to import specific Classes or Interfaces from the java package e.g java.time.LocalDate. IntelliJ marks this import as an unused import Unused Import java.time.LocalDate

After I replace the LocalDate with an Wildcard * the Message is gone java.time.*

In the next Step I did the same with another Class I want to import. This time I used the java.util.Set import. The same message occurred after I wrote Set<TestClass> foo;. Cannot resolve Symbol 'Set'

When I replaced the java.util.Set with java.util.* the Message disappeared. Wildcard import for java.util

I got this Problem everytime I want to import a specific Class from the Java JDK libraries. When I import libraries from the Gradle Dependencies everythings works fine. So this Problem only occurs on Java libraries.

I Already tried the following Steps to solve the Problem:

Code Sample:

import java.time.LocalDate;
import java.util.*;
import lombok.Getter;
import lombok.Builder;

@Builder
@Getter
public class TestClass {
    private LocalDate testDate;
    private Set<TestClass> foo;
}

Upvotes: 0

Views: 680

Answers (1)

Julian_0920
Julian_0920

Reputation: 11

After Installing Eclipse and getting the same Error Reports like in IntelliJ. I reinstalled jdk 15.0.2. I reopened the project again in IntelliJ and everything worked fine. IntelliJ recommend imports when I used java.util classes. So I will close this question now. Thank you guys very much for trying to help me with this problem. In the end it was something much easier which fixed the problem.

Upvotes: 1

Related Questions