在 Java SE 6 中,新的 java.sql.Wrapper 超介面新增至下列 SQL 介面:
此規則會偵測並標示實作這些介面但沒有 Wrapper 方法的 Java 類別。
任何實作這些 Java 介面的類別中必須新增 Wrapper 方法,才能編譯該類別。
在下列範例中,在新增 isWrapperFor 和 unwrap 方法之前,將會標示 MyClass 類別:
public class MyClass implements javax.sql.DataSource {
public Connection getConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
}
public Connection getConnection(String username , String password) throws SQLException {
// TODO Auto-generated method stub
return null;
}
public PrintWriter getLogWriter () throws SQLException {
// TODO Auto-generated method stub
return null;
}
public void setLogWriter (PrintWriter out) throws SQLException {
// TODO Auto-generated method stub
}
public void setLoginTimeout (int seconds) throws SQLException {
// TODO Auto-generated method stub
}
public int getLoginTimeout () throws SQLException {
// TODO Auto-generated method stub
return 0;
} }
如果要修正這個問題,請在 Eclipse 中,利用 Java 6 或更新版來編譯您的應用程式。 請使用自動化修正程式來新增遺漏的方法,然後手動新增遺漏的實作。 將自訂配置複製到應用程式建置檔,以啟用修正程式自動化。
如需相關資訊,請參閱 java.sql.Wrapper 介面 Java 說明文件。