i have abstract super class , 2 classes extend it
public abstract class myabstract {} public class extends myabstract {} public class b extends myabstract {}
i have interface has method takes subclass of myabstract parameter
public interface myinterface { <t extends myabstract> void somemethod(t param); }
i have class implements interface
public class anotherclass implements myinterface { @override <t extends myabstract> void somemethod(t param) {} }
but want allow specific subclass of myabstract
used in method.
here couple of things tried far:
<t extends a> void somemethod(t param); //doesn't override method void somemethod(a param); //doesn't override method
is there anyway have interface take generic parameter , implementer of interface specify more restricted version of parameter or not possible?
yes, make interface itself take generic parameter:
public interface myinterface<t extends myabstract> { void somemethod(t param); }
then can limit used:
public class anotherclass<t extends a> implements myinterface<t> { @override public void somemethod(t param) {} }
or:
public class anotherclass implements myinterface<a> { @override public void somemethod(a param) {} }
Comments
Post a Comment