fork download
  1. import java.lang.reflect.ParameterizedType;
  2. import java.lang.reflect.Type;
  3. import java.util.Comparator;
  4.  
  5. public class Main {
  6. class MyType {
  7. }
  8.  
  9. class MyComparator implements Comparator<MyType> {
  10. @Override
  11. public int compare(MyType o1, MyType o2) {
  12. return 0;
  13. }
  14.  
  15. @Override
  16. public boolean equals(Object obj) {
  17. return false;
  18. }
  19. }
  20.  
  21. public static void main(String[] args) {
  22. Class<?> klass = MyComparator.class;
  23. Type comparatorType = klass.getGenericInterfaces()[0];
  24. System.out.println(comparatorType.getTypeName());
  25. ParameterizedType preciseType = (ParameterizedType) comparatorType;
  26. System.out.println(preciseType.getActualTypeArguments()[0]);
  27. }
  28. }
  29.  
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
java.util.Comparator<Main$MyType>
class Main$MyType