簡體   English   中英

自動從構造函數中刪除未使用的參數(Eclipse,Java)

[英]Automatically remove unused parameters from constructor (Eclipse, Java)

我有一堆包含未使用參數的構造函數的類。 例如這個:

class Book {

    String author;
    String title;

    public Book(String author, String title, int numberOfPages) {       
        this.author = author;
        this.title = title;
    }
}

Eclipse是否提供自動刪除多個文件中這些未使用參數的方法? 手動刪除它們將花費幾個小時。

在Eclipse Juno上,您可以將編譯器設置為在有未使用的參數時顯示警告/錯誤。

  1. 打開Window -> Preferences
  2. 導航到Java > Compiler -> Errors/Warnings
  3. 查找稱為Unnecessary code的節點
  4. Value of parameter is not used設置Value of parameter is not used Warning或(更好) Error

在此處輸入圖片說明

這樣,如果有未使用的方法/構造函數參數,編譯器將顯示警告,甚至無法編譯。

在這種情況下,當導航到“ Problems視圖時,可以用鼠標右鍵單擊來應用Quick Fix

在此處輸入圖片說明

轉到Windows->Preference->Java->Compiler->Errors/Warnings

在“不必要的代碼”選項卡中。 Value of Parameter is not used作“ IgnoreWarning Error

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM