在Java中获取未检查或不安全的操作
我已经检查了其他类似的问题。但无法理解为什么它会发生在我的代码中:在Java中获取未检查或不安全的操作,java,Java,我已经检查了其他类似的问题。但无法理解为什么它会发生在我的代码中: // Array of lists for Adjacency List Representation LinkedList<Integer> adj[]; // Constructor Prog1(int v) { V = v; array=new String[V]; for(int i=0;i<V;i++) array[i]="*"; adj = ne
// Array of lists for Adjacency List Representation
LinkedList<Integer> adj[];
// Constructor
Prog1(int v) {
V = v;
array=new String[V];
for(int i=0;i<V;i++)
array[i]="*";
adj = new LinkedList[v];
for (int i=0; i<u; ++i) {
adj[i] = new LinkedList<Integer>();
}
}
这条线导致了问题
adj = new LinkedList[v];
这会编译,但会发出警告,因为它是原始类型,这基本上意味着它不是泛型的。但是,
adj = new LinkedList<>[v];
在Java中无效。无法创建泛型类型的数组。而是创建一个ArrayList
IDE通常会告诉您是哪一行导致了问题,并给出如何解决问题的建议。行adj[i]=新的LinkedList将不起作用。@f1sh为什么不起作用?@Nathan看看adj是如何声明的。@f1sh确实是w
ArrayList<ArrayList<Integer>> adj;