Java Class getDeclaredConstructor() 方法

2025 年 3 月 21 日 | 阅读 2 分钟

java Class 类的 getDeclaredConstructoe() 方法返回一个构造函数对象,该对象表示类中存在的所有构造函数。

语法

参数

parameterTypes - 参数数组

返回值

构造函数对象。

抛出

NoSuchMethodException , SecurityException

示例 1

输出

Constructor with no parameter :  public ClassgetDeclaredConstructorExample1()
Constructor with int as parameter type  :  public ClassgetDeclaredConstructorExample1(int)
Constructor with String as  parameter  type  :  private ClassgetDeclaredConstructorExample1(java.lang.String)

示例 2

输出

Default constructor
Constructor  =  public ClassgetDeclaredConstructorExample2(java.lang.Double,java.lang.Long)
 
下一个主题Java类