fork(1) download
  1. import java.util.*;
  2.  
  3. class Example<E> {
  4. E[] array;
  5. Example() { array = newArray(10); }
  6.  
  7. static <E> E[] newArray(int length, E... array) {
  8. return Arrays.copyOf(array, length);
  9. }
  10.  
  11. public static void main(String[] args) {
  12. Example<String> e = new Example<>();
  13.  
  14. try {
  15. String[] s = e.array;
  16. } catch(Exception x) {
  17. x.printStackTrace(System.out);
  18. }
  19. }
  20. }
Success #stdin #stdout 0.1s 320256KB
stdin
Standard input is empty
stdout
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
	at Example.main(Main.java:15)