java - Abstract class generic-through-constructor inheritance -


i'd model following, generic abstract class gets type constructor (ala arraylist())

public abstract class abstractparent<t> {      protected abstractparent(t... params){         //(...)     } }  public child<u,v> extends abstractparent<????>{     public child(u param, v param2){          super(param, param2);     }       } 

but canot use '?' or parent's t '????' type. want child<string,string> abstractparent<string> while child<string,integer> abstractparent<? extends object>,

...similarly how arrays.aslist() method works: aslist("a","b") returns list<string> whereas aslist("a",1) returns list<? extends object>.

why disallowed or how can workaround it?

if want parent type of supertype of both u , v, you'll still have explicitly specify in child's generic parameters. closest thing can class child<x, u extends x, v extends x> extends abstractparent<x>.

you cannot automatically infer common supertype, seem alluding arrays.aslist doing; can't @ type level.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -