Generic Type Arrays in Java Limit PRO

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.

Download Code

Share:

banner for the css playlist in hebrew life michael courses for programmers

The First Steps in CSS

Learn CSS using our our videos (in Hebrew) on the CSS (he) playlist on youtube. Do it now. Do it for free.

Good Trainers Collaborate with Others

It is always essential to keep an open mind and learn from others. This applies to everyone, including teachers and especially software development trainers. Software

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences