0

for example these is a ApiRes class

@Data
public class ApiRes<T> implements Serializable {
    private static final long serialVersionUID = -1657033024659806411L;
    private boolean success;
    private T data;
    private String errorMsg;

we can get these class like that ApiRes.class

but I want to get ApiRes class, how to get it, ApiRes<UserInfo>.class was wrong.

jaymie
  • 53
  • 3

1 Answers1

0

From Why is there no class literal for concrete parameterized types?

Because parameterized type has no exact runtime type representation.

A class literal denotes a Class object that represents a given type. For instance, the class literal String.class denotes the Class object that represents the type String and is identical to the Class object that is returned when method getClass is invoked on a String object. A class literal can be used for runtime type checks and for reflection.

Parameterized types lose their type arguments when they are translated to byte code during compilation in a process called type erasure . As a side effect of type erasure, all instantiations of a generic type share the same runtime representation, namely that of the corresponding raw type . In other words, parameterized types do not have type representation of their own. Consequently, there is no point in forming class literals such as List<String>.class , List<Long>.class and List<?>.class , since no such Class objects exist. Only the raw type List has a Class object that represents its runtime type. It is referred to as List.class.

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89