Unpacking an Array using reflection

后端 未结 2 691
耶瑟儿~
耶瑟儿~ 2021-01-02 05:01

I am trying to unpack an array I obtain from reflecting an objects fields. I set the value of the general field to an Object. If it is an Array I then want to cast my genera

2条回答
  •  萌比男神i
    2021-01-02 06:02

    The only parent class of all arrays is Object.

    To extract the values of an array as an Object[] you can use.

    public static Object[] unpack(Object array) {
        Object[] array2 = new Object[Array.getLength(array)];
        for(int i=0;i

提交回复
热议问题