Parse nested generics, Pleae Help me
Answered
@Data
@ToString(callSuper = true)
public class PageResult<T> extends Result<Collection<T>> {
private static final long serialVersionUID = 1L;
private long total;
private int page;
private int size;
private Collection<T> data;
private int status;
private String message;
}
@Data
public class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
private boolean status = false;
private String message;
private T result;
private String statusCode;
}
The above two are my dtos. When I find PageResut, I get all fields, and the result field is T. Now I want to ask, how can I get that this generic type is Collection<T>, not T. Because in PageResult, Collection<T> has been used instead of T.
Thank you everyone.Please help me.
Please sign in to leave a comment.
Hi,
If I understand you correctly, you can determine it from the "result" field. You just have to check its type.
You can also check com.intellij.psi.PsiSubstitutor and related classes for getting more information about generic type parameters. There are many topics on the forum about it, so you can search for them.