How can I indicate that a generic class extends from one class or another?

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=116055&siteId=1