ChillyBinky
New Member
I wrote some generics with inheritance, but cannot get it to work typesafe. My goal is to provide a general \[code\]BaseService\[/code\] on that I can exection the \[code\]action(base)\[/code\] method, no matter if the \[code\]base\[/code\] object is a \[code\]Foo extends Base\[/code\] or \[code\]Bar extends Base\[/code\].The following does not work, why?\[code\]class Base;class Foo extends Base;interface BaseService<T extends Base> { void action(T base);}class FooService implements BaseService<Foo> { void action(Foo foo) { }}//usage://complains that the method is not applicable for the argument,//and that I should change action(T) to action(Base). Why?Base base;getService().action(base);//just to demonstrate the problemBaseService<? extends Base> getService() { return new FooService();}\[/code\]