我在我的項目中使用了以下代碼。當我使用聲納對其進行評估時,它顯示Unused private method
侵犯了ObjectTypes
內部類中定義的私人構造函數。如果我刪除ObjectTypes
構造函數,它會顯示Hide Utility Class Constructor
違規。請幫助我找到解決此問題的最佳方法。SonarQube違規:內部類私有構造函數未使用私有方法
public final class Constants
{
private Constants()
{
}
public static final String KEY_SEPARATOR = " ~ ";
public static final String COMMON_SEPARATOR = " : ";
public final class ObjectTypes
{
private ObjectTypes()
{
}
public static final String ACTION_CODES = "Action Codes";
public static final String ALL_ACTION_CODES = "All Action Codes";
//more lines
}
}
我可以通過將私有構造函數更改爲Inner類中的受保護構造函數來解決此問題。但是,我認爲在最終的類中使用受保護的構造函數並不是一個好主意。 – Madhujith