M
Marc E
All,
I'm giving generics a shot, and I'm getting this warning: Type safety:
The cast from Object to ArrayList<RequestBean> is actually checking against
the erased type
What I'm wondering is:
1) is this really a problem?
2) Assuming my code is weak, what changes are required to satisfy the
compiler such that I stop receiving the warning?
3) Are generics really beneficial here at all? It seems the only thing I
gained by adding the 4 instances of <RequestBean> was not having to cast to
(RequestBean) in the code that calls this method. Of course, when I remove
all parameters and do it the "old" way, I get the warning "Type safety: The
method get(int) belongs to the raw type ArrayList. References to generic
type ArrayList<E> should be parameterized". But that's neither here nor
there.
Here's the offending code, with the junk removed:
public ArrayList<RequestBean> getPendingRequests(String envIDs,
Integer serverGroupID){
ArrayList<RequestBean> ar_RequestBeans = new
ArrayList<RequestBean>();
ar_RequestBeans = (ArrayList<RequestBean>)
runner.query(cn,sql,h);
return ar_RequestBeans;
}
FYI, runner is an apache DBUtils.QueryRunner object, and query() returns
Object.
Thanks in advance for the teaching.
Marc
I'm giving generics a shot, and I'm getting this warning: Type safety:
The cast from Object to ArrayList<RequestBean> is actually checking against
the erased type
What I'm wondering is:
1) is this really a problem?
2) Assuming my code is weak, what changes are required to satisfy the
compiler such that I stop receiving the warning?
3) Are generics really beneficial here at all? It seems the only thing I
gained by adding the 4 instances of <RequestBean> was not having to cast to
(RequestBean) in the code that calls this method. Of course, when I remove
all parameters and do it the "old" way, I get the warning "Type safety: The
method get(int) belongs to the raw type ArrayList. References to generic
type ArrayList<E> should be parameterized". But that's neither here nor
there.
Here's the offending code, with the junk removed:
public ArrayList<RequestBean> getPendingRequests(String envIDs,
Integer serverGroupID){
ArrayList<RequestBean> ar_RequestBeans = new
ArrayList<RequestBean>();
ar_RequestBeans = (ArrayList<RequestBean>)
runner.query(cn,sql,h);
return ar_RequestBeans;
}
FYI, runner is an apache DBUtils.QueryRunner object, and query() returns
Object.
Thanks in advance for the teaching.
Marc