黑马程序员技术交流社区
标题:
反射 操作数组
[打印本页]
作者:
fmi110
时间:
2015-10-3 09:24
标题:
反射 操作数组
a
package review;
import java.lang.reflect.Array;
public class ReflectArrayDemo {
/**
* 通过放射操作数组
*/
public static void main(String[] args) {
// int[] obj = new int[]{1,2,3};
String[] obj = new String[]{"haha","hehe"};
printArr(obj);
}
private static void printArr(Object obj) {
Class clazz = obj.getClass();
if(clazz.isArray()){
for(int i = 0;i<Array.getLength(obj);i++){
System.out.println(Array.get(obj, i));
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2