java - PagedListHolder<clazz> cannot be resolved to a type -
as know in spring mvc can provide pagination mechanism using pagedlistholder class. did provide methods provide pagination me got forced declare methods of pages because don't know how pass generic type inside methods
here have done:
public class jobs { private pagedlistholder<jobs> jobspagedlist = null; private jobinfo[]jobs = null; .... @requestmapping(value = "jobs/getlatestjobs", method = requestmethod.get) public string providelatesttweet(httpservletrequest request){ ... checking tasks jobs = getlatestjobs(); int firstelement = paginghandlerforlatestjobs(request); }
then here paginghandlerforlatestjobs() implementation :
private int paginghandlerforlatestjobs(httpservletrequest request){ jobspagedlist = new pagedlistholder<jobinfo>(arrays.aslist(jobs)); //========================================================================// //how pass above <jobinfo> classtype parameter inside method ? // //========================================================================// // ... setting setting & returning first page }
i tried below method signature in order accomplish target:
private int paginghandlerforlatestjobs(httpservletrequest request, class clazz)
and try pass argument this:
int firstelement = paginghandlerforlatestjobs(request, jobinfo.class)
however when passing class inside:
new pagedlistholder<clazz>(arrays.aslist(jobs));
i encountered runtime error:
pagedlistholder cannot resolved type
1) problem code has & why can't pass jobinfo inside ?
2) can solve problem using java reflection api ? (if yes how ?)
about problem, no need use reflection, plain generics enough. here's can do:
declare jobspagedlist
different type:
private pagedlistholder<?> jobspagedlist = null;
and method as:
private <t> int paginghandlerforlatestjobs(httpservletrequest request) { jobspagedlist = new pagedlistholder<t>(arrays.aslist(jobs)); /* ... magic */ }
note: if want limit pagedlistholder
receive jobs
, subtypes of it, change declaration <? extends jobs>
, method <t extends jobs>
.
Comments
Post a Comment