### Question:
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);  }### Answer:
@Test public void fromClassToClass() throws Exception { Class c = Cast.toClass(CastTest.class); assertSame(CastTest.class, c); }
@Test public void fromParamClassToClass() throws Exception { Method m = Foo.class.getMethod("foo"); Class c = Cast.toClass(m.getReturnType()); assertSame(Foo.class, c); }
@Test(expected = IllegalArgumentException.class) public void fromParamVarToClass() throws Exception { Method m = Foo.class.getMethod("foot"); Class c = Cast.toClass(m.getGenericReturnType()); assertSame(Foo.class, c); }