[英]Intellij marks all methods as unused even though they are used
Here is part of the code.这是代码的一部分。
public class MyPolynomial {
private double coeffs[];
private int degree;
public MyPolynomial(double ... coeffs) {
if (coeffs != null && coeffs.length > 0) {
this.coeffs = new double[coeffs.length];
System.arraycopy(coeffs, 0, this.coeffs, 0, coeffs.length);
}
//this.coeffs = Arrays.copyOf(coeffs, coeffs.length);
}
public MyPolynomial(String filename) {
Scanner in = null;
try {
in = new Scanner(new File(filename));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
this.degree = in.nextInt();
coeffs = new double[degree+1];
for (int i = 0; i < coeffs.length; i++) {
coeffs[i] = in.nextDouble();
}
}
public String getCoeffs() {
return Arrays.toString(coeffs);
}
}
The class, the constructors, as well as all the methods are marked as unused. class、构造函数以及所有方法都标记为未使用。 But I did use them in the test file.但我确实在测试文件中使用了它们。 It compiles and runs as expected.它按预期编译和运行。
Part of the test file:部分测试文件:
MyPolynomial aTest = new MyPolynomial(1, 2, 3, 4, 5);
System.out.println(aTest.getCoeffs());
System.out.println(aTest.getDegree());
System.out.println(aTest);
我设法通过在文件菜单中使缓存无效来解决此问题。
Doing what Serge Baranov describes here really helped me: IDE incorrectly showing classes and methods as unused Just make sure to select this options in the Invalidate Caches: Invalidate Caches做 Serge Baranov 在这里描述的事情真的帮助了我: IDE 错误地将类和方法显示为未使用只需确保 select 使缓存无效中的这个选项:使缓存无效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.