I created the class Queue with
import java.util.LinkedList;
public class Queue <T>{
private LinkedList<T> list;
public Queue() {
list = new LinkedList<>();
}
...
}
I also created the class Cinema, which has a private field of an array of Queue<String>.
public class Cinema {
private Queue<String>[] arr;
public Cinema() {
arr = new Queue<String>[10];
for (int i = 0; i < 10; i++)
arr[i] = new Queue<String>();
}
...
}
However, the line arr = new Queue<String>[10]; throws a compilation error, saying Cannot create a generic array of Queue<String>. But as I understand it the array isn't generic, as its generic type is defined to be String.
When I change the line to
arr = new Queue[10];
the code works again, although it still gives me a warning saying Type safety: The expression of type Queue[] needs unchecked conversion to conform to Queue<String>[]. So I don't understand why the original doesn't work.