0

codes in java like this "Integer[] integers=new Integer[10];" are fine,when I try codes like "Map.Entry<Integer, Integer>[] entrys=new Map.Entry<Integer, Integer>[number];",I get the following error :

Cannot create a generic array of Map.Entry

then I create a class:

class createTarray<T>{
T[] ts;
@SuppressWarnings("unchecked")
public  createTarray(Class<?> class1,int length) {
ts=(T[])Array.newInstance(class1, length);
}
public T[] getTarray() {
return ts;
}
}

and try to get array with codes bellow:

createTarray<Map.Entry<Integer, Integer>> tarray=new createTarray<Map.Entry<Integer,Integer>>(Map.Entry<Integer,Integer>.class,number);

entrys=tarray.getTarray();

and also get error:

Multiple markers at this line


- Integer cannot be resolved to a variable
    - Map.Entry cannot be resolved to a variable
    - Integer cannot be resolved to a variable
    - Syntax error on token ">", void expected after 
     this token

so could someone help me out? I get quite confused these days by this

wuhui
  • 25
  • 3

0 Answers0