public static <T> Class<T> getClass(T t) {
    @SuppressWarnings("unchecked")
    Class<T> clazz = (Class<T>)t.getClass();
    return clazz;
  }
@Test
  public void testGetClass() {

    //test with Integer
    Integer x = new Integer(42);
    Class<Integer> c = GenericsUtil.getClass(x);
    assertEquals("Correct generic type is acquired from object",
            Integer.class, c);

    //test with GenericClass<Integer>
    GenericClass<Integer> testSubject = new GenericClass<Integer>();
    Class<GenericClass<Integer>> c2 = GenericsUtil.getClass(testSubject);
    assertEquals("Inner generics are acquired from object.",
            GenericClass.class, c2);
  }