fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.lang.reflect.*;
  4. import java.util.*;
  5. import java.util.stream.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9. static String simpleTypeName(Type t) {
  10. if (t instanceof ParameterizedType) {
  11. ParameterizedType p = (ParameterizedType) t;
  12. return simpleTypeName(p.getRawType())
  13. + Stream.of(p.getActualTypeArguments())
  14. .map(Ideone::simpleTypeName)
  15. .collect(Collectors.joining(", ", "<", ">"));
  16. } else if (t instanceof Class) {
  17. Class<?> c = (Class<?>) t;
  18. return c.getSimpleName();
  19. } else {
  20. throw new AssertionError();
  21. }
  22. }
  23.  
  24. static List<String> list() {
  25. throw new AssertionError();
  26. }
  27.  
  28. public static void main(String[] args) throws java.lang.Exception {
  29. Method m = Ideone.class.getDeclaredMethod("list");
  30. System.out.println(simpleTypeName(m.getGenericReturnType()));
  31. }
  32. }
  33.  
Success #stdin #stdout 0.16s 2184192KB
stdin
Standard input is empty
stdout
List<String>