代码:
//反射获取ContextImpl类
Class class2 = Class.forName("android.app.ContextImpl");
Field field2 = class2.getDeclaredField("mServiceCache");
//让final域可修改
field2.setAccessible(true);
if(field2 != null){
//此处Cannot cast from Field to ArrayList
// ((ArrayList)field.clear();
/*此处抛IllegalArgumentException: expected receiver of type android.app.ContextImpl, but got java.lang.Class<android.app.ContextImpl>
field2.set(class2, null);*/
/*空指针异常, expected receiver of type android.app.ContextImpl, but got null
((ArrayList)field2.get(null)).clear();*/