java - Method level generic return types in interfaces -
do method level generics in interfaces (for return types) ever make sense? have use? example:-
public interface abx { public <t> t fx(string p); } i make generic class-level so
public interface abx<t> { public t fx(string p); } is there situation @ want generic method-level in interfaces/abstract classes (for return types).
method level generics have utility. have bind generic type parameter somehow typically such method have generic argument, class, , return generic value. example doesn't this, it's difficult see value of generic type parameter.
you can see examples of them on place - ones come across in jackson databinding class objectmapper - https://fasterxml.github.io/jackson-databind/javadoc/2.2.0/com/fasterxml/jackson/databind/objectmapper.html, such
<t> t readvalue(inputstream is, class<t> returntype) so, value here objectmapper not generically typed class allows me bind any class (provided can understand class , how set various properties based on input). important point there need single instance of objectmapper entire application, don't need 1 every type of object might need databind.
Comments
Post a Comment