Intellij将所有方法标记为未使用,即使它们已被使用

时间:2014-09-10 11:54:33

标签: java intellij-idea

以下是代码的一部分。

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);
    }

}

类,构造函数以及所有方法都标记为未使用。 但我确实在测试文件中使用它们。它按预期编译并运行。

部分测试文件:

MyPolynomial aTest = new MyPolynomial(1, 2, 3, 4, 5);
    System.out.println(aTest.getCoeffs());
    System.out.println(aTest.getDegree());
    System.out.println(aTest);

1 个答案:

答案 0 :(得分:14)

我设法通过在“文件”菜单中使缓存无效来解决此问题。