【发布时间】:2017-01-09 08:10:30
【问题描述】:
这是我第一次使用反射,不知道我在实例化受保护的构造函数时犯了什么错误。下面是我实例化JsonProcessingException 的构造函数的代码。
getDeclaredConstructor 导致 NoSuchMethodException,尽管此异常类具有带一、二和三参数的受保护构造函数。
final Constructor<JsonProcessingException> constructor =
JsonProcessingException.class
.getDeclaredConstructor(Object.class, Object.class);
constructor.setAccessible(true);
我的假设:我读到我们可以使用反射来实例化私有构造函数,所以我假设 protected 也可以实例化。
【问题讨论】:
标签: java reflection constructor protected