GenericsUtil { public static <T> Class<T> getClass(T t) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>)t.getClass(); return clazz; }  static Class<T> getClass(T t); static T[] toArray(Class<T> c, List<T> list); static T[] toArray(List<T> list); static boolean isLog4jLogger(Class<?> clazz);  }
@Test public void testGetClass() { Integer x = new Integer(42); Class<Integer> c = GenericsUtil.getClass(x); assertEquals("Correct generic type is acquired from object", Integer.class, c); GenericClass<Integer> testSubject = new GenericClass<Integer>(); Class<GenericClass<Integer>> c2 = GenericsUtil.getClass(testSubject); assertEquals("Inner generics are acquired from object.", GenericClass.class, c2); }