java - Generic class to array of generics of same generic type -


i have method signature like

public <t extends someclass> t[] findall(class<t> oclass, string condition) 

but i'm not sure how can create t[] type class<t>. i've tried using collection<t> cannot cast (t[]) collection.toarray() , array.newinstance(class<?>, int) asks array class (i.e. t[]) already, of no use , redundant.

also, obvisously, new t[n] not work.

i presume it's easy, i'm numb solution right :)

thanks.

newinstance not ask array class, asks component type. work fine, albeit usual problems unchecked casts , generic arrays.

t[]  myarr = (t[]) array.newinstance(oclass, length); 

but why mix arrays , generics @ all? it'll lead headaches. use collections api, list.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -