www.pudn.com > ThinkinginJava4thEdition(SourceCode).zip > ArrayOfGenericType.java


//: arrays/ArrayOfGenericType.java 
// Arrays of generic types won't compile. 
 
public class ArrayOfGenericType { 
  T[] array; // OK 
  @SuppressWarnings("unchecked") 
  public ArrayOfGenericType(int size) { 
    //! array = new T[size]; // Illegal 
    array = (T[])new Object[size]; // "unchecked" Warning 
  } 
  // Illegal: 
  //! public  U[] makeArray() { return new U[10]; } 
} ///:~