fork download
  1. import java.util.Arrays;
  2.  
  3. class Ideone
  4. {
  5. public static <E> void genericMethod(E e) {
  6. final int size = 2;
  7. Object[] objectArr = new Object[size];
  8. objectArr[0] = "foobar";
  9.  
  10. @SuppressWarnings("unchecked")
  11. E[] integerArr = (E[]) objectArr;
  12. integerArr[1] = e;
  13.  
  14. System.out.println(Arrays.toString(integerArr));
  15. System.out.println(e.getClass().getName());
  16. System.out.println(integerArr.getClass().getName());
  17. }
  18.  
  19. public static void main(String[] args) {
  20. genericMethod(new Integer(5));
  21. }
  22. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
[foobar, 5]
java.lang.Integer
[Ljava.lang.Object;