java - Is there benefit in a generified interface? -
recently in answer suggested me this:
public interface operation<r extends operationresult, p extends operationparam> { public r execute(p param); } is better this:
public interface operation { public operationresult execute(operationparam param); } i can't see benefit in using first code block on second 1 ...
given both operationresult , operationparam interfaces implementer needs return derived class anyway , seems quite obvious me.
so see reason use first code block on second 1 ?
this way can declare operation implementations return more specific result, e.g.
class sumoperation implements operation<sumresult, sumparam> though whether of value application depends entirely on situation.
update: of course return more specific result without having generic interface, way can restrict input parameters well.
Comments
Post a Comment