简体   繁体   English

IntelliJ IDEA无法解析静态导入

[英]IntelliJ IDEA cannot resolve static import

When I import regularly it works as expected: 我定期导入它按预期工作:

在此输入图像描述

However, if I change an import to static , IDEA cannot resolve it: 但是,如果我将导入更改为static ,则IDEA无法解析:

在此输入图像描述

Gradle builds the project successfully. Gradle成功构建项目。

It seems to be a problem with IDEA but I can't find if it is a known problem. 它似乎是IDEA的一个问题,但我无法找到它是否是一个已知的问题。 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 我使用IntelliJ IDEA community 2016.2.4和java版本1.7.0_79

You either want to do this, which will import all of the static members of Assert 您要么这样做,要导入 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 : 我猜你的意思是静态导入属于org.junit.Assert所有方法:

import static org.junit.Assert.*;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM