Disallowed generic array creation in Java -


i thought understood not create arrays of generic classes in java few examples have seen lately have confused me. can explain? thanks!

i have generic class defined as: public class bag<item> implements iterable<item>

now in class called edgeweightedgraph (below), making array of bag , that's compiling fine. if bag wasn't generic class, know should have been fine here, is. why compiler not throwing error?

public class edgeweightedgraph {  private final int v; private final bag[] adj;      public edgeweightedgraph(int v) {         this.v = v;         adj = new bag[v];     } } 

while throwing error in generic class defined as:

public class minpq<key extends comparable<key>> {  private key[] pq;      public minpq() {         pq = new key[2];     } } 

in edgeweightedgraph, line not create generic array.

adj = new bag[v]; 

it creating array of raw type, allowed. bag class, not type parameter.

however, in minpq, key type parameter, not class, line attempts create generic array , compiler error.

pq = new key[2]; 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -