我試圖製作一個方法,其參數爲Country.class
,User.class
等,並返回argument.count()
。在Java中傳遞一個類(「Country.class」)作爲參數
我給這個方法的所有可能的類從Model
延伸並且具有方法count()
。
我的代碼:
private static long <T> countModel(Model<T> clazz)
{
// there is other important stuff here, which prevents me from
// simply by-passing the method altogether.
return clazz.count();
}
通過調用:
renderArgs.put("countryCount", countModel(Country.class));
但是,這是行不通的。
請問我該怎麼做?
我不明白你在問什麼,'Country.class'是'Class',並沒有任何'count()'。你能用簡單的英語來重述你的問題嗎? – 2010-05-22 20:36:46
你除了有一個特定的靜態方法的類嗎?這是一個非常奇怪的設計。 – whiskeysierra 2010-05-22 21:51:38