日期:2014-05-20  浏览次数:20705 次

请教反射问题,如何得到类中的数组,先谢谢大家了。
请教反射问题,如何得到类中的数组,先谢谢大家了。

public   class   PropertyArray   {

        private   String[][]   inputVoltage;
        private   String[][]   powerType;
        private   String[][]   shellType;
        private   String[][]   groundType;
        private   String[][]   adjustType;
        private   String[][]   protectType;
        .
        .
        .
        public   void   test(){
              Abc   abc   =   new   Abc();
              for(){
                      abc.abcd(String[][]   array);
                      //在次遍历自己所有的Strin[][]类型字段,
                      //作为参数调用abc.abcd(String[][]   array)。
              }
        }

}

public   class   Abc(){
        .
        .
        .
        public   void   abcd(String[][]   array){

        }

}

呵呵,不知道我的问题说清楚没有。

------解决方案--------------------
我是这么认为的,reflection机制能够查找class中的所有对象,如methods,fileds
你可以在你的构造类中,如你的PropertyArray类中,
定义类
Class test= Class.forName( "PropertyArray ");
遍历
Field fl[]= test.getDeclaredFields();
for (int i= 0; i < fl.length; i++)
{
Field perfl= fieldlist[i];
}
------解决方案--------------------
我好象看见过对象序列化或是用集合类来做的,不知到能不能帮上你

------解决方案--------------------
具体我没有试验过,但是我想既然已经得到了这个对象,为什么不能cast呢?
------解决方案--------------------
不知道怎么做的。。。有待高手解决