When using an array of generic type objects in Java we cannot specify the exact parametric type. This limit exists due to the way generics is implemented in Java (in the compiler level).
package il.ac.hit.samples; public class ArraysGenericsLimit { public static void main(String[] args) { MyStack<?> []vec = new MyStack<?>[10]; vec[0] = new MyStack<Rectangle>(); vec[1] = new MyStack<Rectangle>(); } }
The following short video clip shows that.