When I import regularly it works as expected:
However, if I change an import to static
, IDEA cannot resolve it:
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
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.
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.
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;
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.*;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With