fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.lang.reflect.*;
  4.  
  5. public class Main {
  6.  
  7. public static void main (String[] args) throws Exception {
  8. TestDto<Integer> a = new TestDto<Integer>(){};
  9. TestDto<String> b = new TestDto<String>(){};
  10. System.out.println(a.getTypeParameter());
  11. System.out.println(b.getTypeParameter());
  12. }
  13. }
  14.  
  15. class TestDto<T> {
  16. public Type getTypeParameter() {
  17. return ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
  18. }
  19. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
class java.lang.Integer
class java.lang.String