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 :
答案 0 :(得分:4)
您的方法的参数必须是数组
public static <T> void print_generic(T[] arr) { }