在反射中关于构造器相关接口比较多,繁琐。这里罗列一下,各自区别
类别 | 方法名字 | |
有Declared (可获取公有,私有) | getDeclaredConstructor() | 1、单数 2、获取所有无参构造方法,公有,私有 |
getDeclaredConstructors() | 1、复数 2、获取所有构造方法,包括:无参,有参数,公有,私有 | |
没有Declared (只能获取公有) | getConstructor() | 1、单数 2、获取公有无参构造方法 3、当类没有 公有无参构造方法,抛异常 |
getConstructors() | 1、复数 2、获取所有公有构造方法,包括有参,无参 |