在编写一些java代码时,我遇到了一个我无法识别的异常,即java.lang.VerifyError.一些谷歌搜索表明这通常是一个jvm/javac错误,我很好奇,如果我的情况是.
我怀疑的是
private Pair<Integer/*used size*/,Pair<K,V[]>[]>[] map=(Pair<Integer,Pair<K,V[]>[]>[])Array.newInstance(Pair.class,63);//good start number
Run Code Online (Sandbox Code Playgroud)
和
map[b]=new Pair<Integer,Pair<K,V[]>[]>(7,(Pair<K,V[]>[])Array.newInstance(Pair.class,7));
Run Code Online (Sandbox Code Playgroud)
但我很不确定.
这是编译器错误还是我的代码有问题.
这些行是我在某处找到的泛型数组创建失败的解决方法.
附加代码.
package osm2spacebook;
import java.util.Iterator;
import java.lang.reflect.Array;
import java.util.NoSuchElementException;
public class MultiMap<K,V> implements Iterable<K>{
private int num_keys;
@SuppressWarnings("unchecked")
private Pair<Integer/*used size*/,Pair<K,V[]>[]>[] map=(Pair<Integer,Pair<K,V[]>[]>[])Array.newInstance(Pair.class,63);//good start number
@SuppressWarnings("unchecked")
private int bucket(K key){//position in bucket
int h=key.hashCode();
int b=h%map.length;
if(map[b]==null)
map[b]=new Pair<Integer,Pair<K,V[]>[]>(7,(Pair<K,V[]>[])Array.newInstance(Pair.class,7));
return b;
}
private int position(K key){//position within bucket
int b=bucket(key);//IMPORTANT this must use the buket function to obtain this otherwise it is a race
for(int i=0;i<map[b].v1;i++)
if(map[b].v2[i].v1==key) …Run Code Online (Sandbox Code Playgroud)