我无法为此正确编写通用方法:
private int [] loadIntArray(String key, int [] defaultArray) {
int [] array = new int [4];
for( int index=0; index<4 ; index++) {
array[index] = sp.getInt(key + index, defaultArray[index]);
}
return array;
}
我写了这个:
private <T[]> loadArray(String key, <T[]> defaultArray) {
<T[]> array = new <T[LEVELS]>;
for( int index=0; index<4 ; index++) {
array[index] = sp.getInt(key + index, defaultArray[index]);
}
return array;
}
但它不编译。
我收到几个错误,“缺少方法的返回类型”,“私有令牌后预期的类型”。
写它的正确方法是什么?