Java Generics - ไม่มีอาร์เรย์

ไม่อนุญาตให้ใช้อาร์เรย์ประเภทพารามิเตอร์

//Cannot create a generic array of Box<Integer>
Box<Integer>[] arrayOfLists = new Box<Integer>[2];

เนื่องจากคอมไพเลอร์ใช้ type erasure พารามิเตอร์ type จึงถูกแทนที่ด้วย Object และผู้ใช้สามารถเพิ่มอ็อบเจ็กต์ประเภทใดก็ได้ในอาร์เรย์ และในรันไทม์โค้ดจะไม่สามารถโยน ArrayStoreException ได้

// compiler error, but if it is allowed
Object[] stringBoxes = new Box<String>[];
  
// OK
stringBoxes[0] = new Box<String>();  

// An ArrayStoreException should be thrown,
//but the runtime can't detect it.
stringBoxes[1] = new Box<Integer>();