java - extending a class where a parameter of the parent class extends a class -
i trying extend version of treemap subclass index words more efficiently, unsure correct syntax is. class definition treemap looks this
public class mytreemap<k extends comparable<? super k>,v> extends abstractmap<k,v> {
extending class in straightforward way
public class treemapindexer<k> extends mytreemap<k,linkedlist<integer>> {
yields error "bound mismatch: type k not valid substitute bounded parameter > of type mytreemap".
i tried
public class treemapindexer<k> extends mytreemap<k extends comparable<? super k>, linkedlist<integer>> {
instead, yields compiler error "syntax error on token "extends", , expected". erroneous extends in "".
i found thread (generic generics: "syntax error on token "extends", , expected") same error message. appears different situation mine, tried
public class treemapindexer<k> extends mytreemap<k, k extends comparable<? super k>, linkedlist<integer>> {
which yields same "syntax error on token "extends", , expected" compiler message.
class mytreemap<k extends comparable<? super k>, v> extends abstractmap<k, v>
so k
declared bound of extends comparable<? super k>
. need redeclare same bound on subclass.
class treemapindexer<k extends comparable<? super k>> extends mytreemap<k, linkedlist<integer>>
otherwise attempting declare subtype not having restriction compilation error 'bound mismatch'.
what tried right, bound needed in generic type declaration, not arguments (passed along) superclass.
Comments
Post a Comment