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));
- }
- }
- }
- }
复制代码
|
|