fork(1) download
  1. import java.io.*;
  2. import java.lang.reflect.*;
  3. import java.util.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone {
  7. static class TypeToken<T> {
  8. Type getType() {
  9. ParameterizedType t = (ParameterizedType) getClass().getGenericSuperclass();
  10. return t.getActualTypeArguments()[0];
  11. }
  12. }
  13.  
  14. public static void main(String[] args) {
  15. Collection<Integer> list = new ArrayList<>();
  16. System.out.println(list.getClass().getGenericInterfaces()[0]);
  17.  
  18. TypeToken<Collection<Integer>> tt = new TypeToken<Collection<Integer>>() {};
  19.  
  20. System.out.println(tt.getClass().getGenericSuperclass());
  21. System.out.println(tt.getType());
  22. }
  23. }
  24.  
Success #stdin #stdout 0.11s 28016KB
stdin
Standard input is empty
stdout
java.util.List<E>
Ideone.Ideone$TypeToken<java.util.Collection<java.lang.Integer>>
java.util.Collection<java.lang.Integer>