Tlaloc-ES :
Hi I have the next class
public class ApiResponse<T extends ApiResponseData >
When T
is a type of the ApiResponseData
, but sometimes I receive to a list instead of an object and for this case I need the T
to be extended from ApiResponseData
or List<ApiResponseData>
how can do it this?
My attempt
public class ApiResponse<T extends ApiResponseData || T extends List<ApiResponseData>>
Amit Bera :
It is not possible as because it will be ambiguous for java to decide which class to use during type erasing. You can use Generic to specify the constraint like T needs to be a subclass of multiple class like (A & B) like <T extends A & B>
but your use case not possible.