我有一個不太好的遺留代碼涉及使用私有靜態類的方法我想知道是否可以調用此類中的方法。我正在爲其寫作測試。 我知道這可以用反射來完成,如果這是一種方法,但它不是。來自私有靜態嵌套類的調用方法
public class FiscalReport implements Report
{
private void readProductValueClass()
{
Connection dbc = null;
Statement st = null;
ResultSet rs = null;
String q = null;
try
{
dbc = db.getConnection();
dbc.setAutoCommit(false);
st = dbc.createStatement();
routerClassMap = new HashMap();
q = "SELECT * FROM sales_report";
rs = st.executeQuery(q);
while(rs.next())
{
ProductValueClassrc = new ProductValueClass(); // <---this new class
// is where it gets called...
.....
}
private static class ProductValueClass
{
public String name;
public String emp;
public String sale;
public String option;
public String value;
public Query q;
public Query qr
public Query sql;
public String toString()
{
return
"[" +
name + ", " +
emp + ", " +
sale + ", " +
option + ", " +
values +
"]";
}
public Query query()
{
return q.add(q(notEqual(qr)? null: sql));
}
}
}
「靜態內部」是矛盾的。不清楚它爲什麼是嵌套類。不清楚你在問什麼。 – EJP
我假設他們的意思是靜態嵌套類。 – Emz
請提供代碼示例,您需要在哪裏調用ProductValueClass的方法 –