Java generics: get class of generic method's return type
问题 Background I once wrote this method: private <T> SortedSet<T> createSortedSet() { return new TreeSet<T>(); } It's supposed to be called like this: Set<String> set = createSortedSet(); This works fine (although I've seen in answers here when researching the current question that this is error-prone). The current situation Anyway, now I am writing the following code (in a class that extends javax.servlet.jsp.tagext.TagSupport): private <T> T evaluate(String expression) { ExpressionEvaluator