标签:exception image row void dex tac col declare exce
通过这个方法可以将私有的方法,进行获取出来
实体类:
package com.qingmu.alipay4.utils; /** * @Auther:qingmu * @Description:脚踏实地,只为出人头地 * @Date:Created in 19:52 2019/8/8 */ public class AccessibleTest { private int age; private String name; private String heigh; public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getHeigh() { return heigh; } public void setHeigh(String heigh) { this.heigh = heigh; } }
使用暴力反射的方法:
package com.qingmu.alipay4.utils; import java.lang.reflect.Field; /** * @Auther:qingmu * @Description:脚踏实地,只为出人头地 * @Date:Created in 19:53 2019/8/8 */ public class Main { public static void main(String[] args) throws IllegalAccessException, ClassNotFoundException { Class<?> aClass = Class.forName("com.qingmu.alipay4.utils.AccessibleTest"); AccessibleTest accessibleTest = new AccessibleTest(); accessibleTest.setAge(18); accessibleTest.setName("huahua"); for (Field declaredField : aClass.getDeclaredFields()) { declaredField.setAccessible(true); System.out.println(declaredField.get(accessibleTest)); } } }
下面的效果图:
标签:exception image row void dex tac col declare exce
原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/11324359.html