java不能在泛型方法中的数组传递中使用arr.length
public class Main {
public static void main(String[] args) {
Integer[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
print_generic(arr);
}
public static <T> void print_generic(T arr) {
// for (int i = 0; i < arr.length; i++) { //ERROR
// System.out.print(arr[i] + " ");
// }
System.out.println();
System.out.print(arr);
}
}
错误:无法解析符号长度
什么是问题
请告诉我我做错了什么
java visualizer image: even both the arr refers to the same object :
# 1 楼答案
方法的参数必须是数组