2015-04-20 15:36:01 -07:00
|
|
|
|
//: arrays/ArrayOfGenericType.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
// Arrays of generic types won't compile.
|
|
|
|
|
|
|
|
|
|
public class ArrayOfGenericType<T> {
|
|
|
|
|
T[] array; // OK
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public ArrayOfGenericType(int size) {
|
|
|
|
|
//! array = new T[size]; // Illegal
|
|
|
|
|
array = (T[])new Object[size]; // "unchecked" Warning
|
|
|
|
|
}
|
|
|
|
|
// Illegal:
|
|
|
|
|
//! public <U> U[] makeArray() { return new U[10]; }
|
|
|
|
|
} ///:~
|