Search code examples
javaintellij-idea

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

Solution

  • I managed to solve this problem by invalidating caches in the File menu.