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 java.lang.Exception
  8. {
  9. TestDto<Integer> a = new TestDto<Integer>();
  10. TestDto<String> b = new TestDto<String>();
  11. System.out.println(a.getTypeParameter());
  12. System.out.println(b.getTypeParameter());
  13. }
  14. }
  15.  
  16. class TestDto<T> {
  17. public Type getTypeParameter() {
  18. return new TestDto<T>() {
  19. public Type getTypeParameter() {
  20. return ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
  21. }
  22. }.getTypeParameter();
  23. }
  24. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
T
T