|
package net.qi.test.thread;
public class Tes {
public static void main(String[] args) {
int type[] ={};
String str[]={"1","2","3","4","5","6"};
// Object 数组
Object[] obj = null;
// 数组应有的长度
int length = str.length;
// String 类型或数组
if (type.getClass().equals(String.class) || type.getClass().equals(String[].class)) {
obj = new String[length];
for (int i = 0; i < obj.length; i++) {
obj = str;
}
} else if (type.getClass().equals(int.class) || type.getClass().equals(int[].class)) { // int 类型或数组
obj = new Integer[length];
for (int i = 0; i < obj.length; i++) {
obj = Integer.parseInt(str); //这里报错Type mismatch: cannot convert from int to Object
}
}
for (int i = 0; i < obj.length; i++) {
System.out.println(obj);
}
}
} |
|