@Test public void fromParamClassToClass() throws Exception { Method m = Foo.class.getMethod("foo"); Class c = Cast.toClass(m.getReturnType()); assertSame(Foo.class, c); }
public static Class toClass(Type type) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; return (Class) pt.getRawType(); } if (type instanceof TypeVariable) { throw new IllegalArgumentException("trying to get annotations from type declaration " + type + " from declaration " + ((TypeVariable) type).getGenericDeclaration()); } return (Class) type; }
Cast { public static Class toClass(Type type) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; return (Class) pt.getRawType(); } if (type instanceof TypeVariable) { throw new IllegalArgumentException("trying to get annotations from type declaration " + type + " from declaration " + ((TypeVariable) type).getGenericDeclaration()); } return (Class) type; } }
Cast { public static Class toClass(Type type) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; return (Class) pt.getRawType(); } if (type instanceof TypeVariable) { throw new IllegalArgumentException("trying to get annotations from type declaration " + type + " from declaration " + ((TypeVariable) type).getGenericDeclaration()); } return (Class) type; }  }
Cast { public static Class toClass(Type type) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; return (Class) pt.getRawType(); } if (type instanceof TypeVariable) { throw new IllegalArgumentException("trying to get annotations from type declaration " + type + " from declaration " + ((TypeVariable) type).getGenericDeclaration()); } return (Class) type; }  static Class toClass(Type type); }
Cast { public static Class toClass(Type type) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; return (Class) pt.getRawType(); } if (type instanceof TypeVariable) { throw new IllegalArgumentException("trying to get annotations from type declaration " + type + " from declaration " + ((TypeVariable) type).getGenericDeclaration()); } return (Class) type; }  static Class toClass(Type type);  }