java Android 反射得到的变量为什么用两次强制类型转换(Object[]) ((Object[])的到原来的类型

问题描述

Android 热修复中替换DexPathList中的dexElements字段
下面 代码中为什么用了两次数组类型的强制转换(Object[]) ((Object[]),而不是一次

问题出现的环境背景及自己尝试过哪些方法

相关代码

jlrField 是反射得到的DexPathList中的dexElements字段,这个字段不是Element[]类型吗



        Object[] original = (Object[]) ((Object[]) jlrField.get(instance));
        System.out.println("-----------------");
        System.out.println(original.getClass());    //class [Ldalvik.system.DexPathList$Element;
        System.out.println(original.getClass().getComponentType()); //class dalvik.system.DexPathList$Element
        Object[] combined = (Object[]) ((Object[]) Array.newInstance(original.getClass()
                .getComponentType(), original.length + extraElements.length));
        System.arraycopy(original, 0, combined, 0, original.length);
        System.arraycopy(extraElements, 0, combined, original.length, extraElements.length);
        jlrField.set(instance, combined);

你期待的结果是什么?实际看到的错误信息又是什么?

阅读 849
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题