本帖最后由 杨杨 于 2013-3-3 13:57 编辑
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
-
- int[] a1=new int[3];
- int[] a2=new int[4];
- int[][] a3=new int[3][4];
- String[] a4= new String[4];
- System.out.println(a1.getClass()==a2.getClass());
- System.out.println(a1.getClass()==a3.getClass());//Incompatible operand types Class<capture#3-of ? extends int[]> and Class<capture#4-of ? extends int[][]>
- System.out.println(a1.getClass()==a4.getClass());//Incompatible operand types Class<capture#5-of ? extends int[]> and Class<capture#6-of ? extends String[]>
-
- }
- private static void ChangerVale(Object obj) throws Exception {
- Field[] fields= obj.getClass().getFields();//getDeclaredFields();
- System.out.println(fields.length);
- for(Field field:fields){
- if(field.getType()==String.class){
- String oldchar= (String)field.get(obj);
- String newString =oldchar.replace('b', 'a');// "a" "b" 与 'a' 'b'区别
- field.set(obj, newString);
- }
-
- }
- }
复制代码 是都是class 对象 应该能比较类型 张老师讲的时候不报错我写的时候报编译时异常
是java jdk改进了还是我写错了 |