I query a database and get a Bean class, which returns ArrayList<Object>
. However I
public static ArrayList<Object> getBeanList(){
String sql = "....";
ArrayList<Object> beanList = DBUtil.getBeanList(sql, new ConfDetailsBean());
return beanList;
}
In the calling function of above helper method, I have to cast ArrayList<Object>
to required class before I can work the beanList:
ArrayList<Object> beanObjList = getBeanList(); //helpermethod call
ArrayList<ConfDetailsBean> confDetailsBeanList = new ArrayList<ConfDetailsBean>();
for(Object bean: beanList)
confDetailsBeanList.add((ConfDetailsBean) bean);
Now, in helper method DBUtil.getBeanList(sql, new ConfDetailsBean());
, ConfDetailsBean is hardcoded.
How to make the helper method generic, so that I can pass any Bean Object?