Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA cannot resolve static import

When I import regularly it works as expected:

enter image description here

However, if I change an import to static, IDEA cannot resolve it:

enter image description here

Gradle builds the project successfully.

It seems to be a problem with IDEA but I can't find if it is a known problem. I tried cleaning, invalidate caches etc. Anything else I can do?

Im using IntelliJ IDEA community 2016.2.4 and java version 1.7.0_79

like image 797
Thomm Avatar asked Oct 18 '16 10:10

Thomm


People also ask

Do not import * IntelliJ?

To avoid IntelliJ IDEA replacing imports with * , you need to configure the Class count to use import with '*' and Names count to use static import with '*' preferences: Go to Preferences > Editor > Code Style > Java.

How do I stop IntelliJ from optimizing imports?

5 Answers. Show activity on this post. Disable File | Settings | Editor | General | Auto Import | Optimize imports on the fly. Normally you don't need to add imports manually, IDEA does it for you.


2 Answers

You either want to do this, which will import all of the static members of Assert

import static org.junit.Assert.*;

Or, to get a specific method

import static org.junit.Assert.assertEquals;
like image 111
Ash Avatar answered Sep 30 '22 21:09

Ash


Your syntax is wrong - static imports are for static methods, not for classes. I'm guessing you meant to statically import all the methods belonging to org.junit.Assert:

import static org.junit.Assert.*;
like image 34
Mureinik Avatar answered Sep 30 '22 21:09

Mureinik