java 访问对象私有变量

Captcha captcha = getCaptcha(captchaId);
   
// 通过反射获取验证码值
Class<?> classType = captcha.getClass();
Field field;
field = classType.getDeclaredField("response");
field.setAccessible(true); // 抑制Java对修饰符的检查
logger.debug("反射得到的验证码:{}", field.get(captcha));
原文地址:https://www.cnblogs.com/mengjianzhou/p/8669488.html