2014-09-10 16 views
5

以下是代碼的一部分。Intellij將所有方法標記爲未使用,即使它們已被使用

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); 
+0

也許你可以檢查你的IDE供應商,這似乎沒有編程問題。 – Smutje 2014-09-10 11:58:23

+0

不確定testfiles是否被視爲「正在使用」,因爲該代碼未在實際應用程序中使用 – 2014-09-10 12:04:21

+0

我使用MyPolynomial類和MyPolynomailTest類創建了一個簡單的項目,它對我來說都很好。 'MyPolynomial'類被標記爲正在使用以及類中的方法。嘗試從「文件」菜單中使緩存失效。 – maba 2014-09-10 12:39:25

回答

10

我設法在文件菜單無效緩存來解決這個問題。

+0

這個答案出現在低質量的審查隊列中。如果你詳細說明你如何解決你的問題(在你的答案中),你更有可能獲得upvotes! – 2014-09-10 14:54:54

相關問題