类的类getConstructor()方法 (Class class getConstructor() method)

  • getConstructor() method is available in java.lang package.

    getConstructor()方法在java.lang包中可用。

  • getConstructor() method is used to return a Constructor object that reflects the given public constructor of the class denoted by this Class object.

    getConstructor()方法用于返回一个Constructor对象,该对象反映此Class对象表示的类的给定公共构造方法。

  • getConstructor() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    getConstructor()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • getConstructor() method may throw an exception at the time of returning a Constructor object.

    返回一个Constructor对象时, getConstructor()方法可能会引发异常。

    • NoSuchMethodException: In this exception when a specifying method does not exist.NoSuchMethodException :在此异常中,当指定方法不存在时。
    • SecurityException: In this exception, it may raise when the security manager exists.SecurityException :在此异常中,当安全管理器存在时可能会引发此异常。

Syntax:

句法:

    public Constructor getConstructor (Class ...paramType);

Parameter(s):

参数:

  • Class ...paramType – represents the parameter array.

    Class ... paramType –表示参数数组。

Return value:

返回值:

The return type of this method is Constructor, it returns Constructor object of the public constructor that meets the given parameter types.

此方法的返回类型为Constructor ,它返回满足给定参数类型的公共构造方法的Constructor对象。

Example:

例:

// Java program to demonstrate the example
// of Constructor getConstructor (Class ...paramType) method of Class
import java.lang.reflect.*;
public class GetConstructorOfClass {public static void main(String[] args) throws Exception {// Creating an array of Class type
Class[] cl = new Class[] {String.class
};
// It return the Constructor object that denotes
// the public Constructor of the class denoted by
// the Class object
Constructor con = String.class.getConstructor(cl);
// Display public Constructor of String Class
System.out.println("Constructor of the Class: " + con);
}
}

Output

输出量

Constructor of the Class: public java.lang.String(java.lang.String)

翻译自: https://www.includehelp.com/java/class-class-getconstructor-method-with-example.aspx

Java类类getConstructor()方法及示例相关推荐

  1. java.util.zip 用法,Java压缩文件工具类ZipUtil使用方法代码示例

    本文实例通过Java的Zip输入输出流实现压缩和解压文件,前一部分代码实现获取文件路径,压缩文件名的更改等,具体如下: package com.utility.zip; import java.io. ...

  2. java散列法的运用实例,Java HashMap compute() 使用方法及示例

    Java HashMap compute() 使用方法及示例 Java HashMap compute()方法计算一个新值,并将其与哈希映射中的指定键相关联. compute()方法的语法为: has ...

  3. math的用法在java中的使用,Java Math cbrt() 使用方法及示例

    Java Math cbrt() 使用方法及示例 Java Math cbrt()方法返回指定数字的立方根. cbrt()方法的语法为: Math.cbrt(double num) 注意:cbrt() ...

  4. java arraylist 方法返回值,Java ArrayList get() 使用方法及示例

    Java ArrayList get() 使用方法及示例 Java ArrayList get()方法返回指定位置存在的元素. get()方法的语法为: arraylist.get(int index ...

  5. java kryo_Kryo框架使用方法代码示例

    Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...

  6. java readtimeout_Java HttpURLConnection.getReadTimeout方法代码示例

    import java.net.HttpURLConnection; //导入方法依赖的package包/类 /** * 得到响应对象 * * @param urlConnection * @retu ...

  7. java invalidate_Java Component.invalidate方法代码示例

    import java.awt.Component; //导入方法依赖的package包/类 /** Installs the component we will embed to display t ...

  8. java hasmoreelements_Java IOException.hasMoreElements方法代码示例

    import java.io.IOException; //导入方法依赖的package包/类 /** * fileName���� ���� package �������� ������ ���� ...

  9. java singletonlist_Java Collections singletonList()方法及示例

    集合类singletonList()方法 (Collections Class singletonList() method) singletonList() method is available ...

  10. Java Math toIntExact() 使用方法及示例 long转int

    Java Math toIntExact()方法从指定的long参数返回int值. toIntExact()方法的语法为: Math.toIntExact(long value) 注意:toIntEx ...

最新文章

  1. java url json字符串_使用HttpClient将URL中的JSON查询字符串发送到Web服务(Java)
  2. 使用OpenCV和Python高效计算视频的总帧数
  3. 数据库和数据湖的关键概念性差异
  4. 算法学习之路|完美数列
  5. 利用__FILE__, __LINE__, __FUNCTION__跟踪调试程序
  6. MySQL使用concat实现连接
  7. 28. css样式中px转rem
  8. Linux PWN从入门到熟练
  9. python可视化使用_python可视化pyecharts
  10. Linux安装包下载地址(国内)
  11. Nginx源码分析 - Event事件篇 - Event模块的进程初始化(18)
  12. Java compiler level does not match the version of the installed Java project facet.问题
  13. (亲测有效)windows10和11如何卸载Microsoft Edge浏览器
  14. C语言方波转换正弦波,方波转换成正弦波电路
  15. kettle同步数据 (SAP hana到 Mysql)
  16. Linux下设置MTU值到9000
  17. 基于Matlab的压力控制论文,基于Matlab的压力容器螺栓组联接优化设计的论文
  18. linux网站权限恢复,RMAN异机恢复——备份集权限问题
  19. Qemu连接外网的配置方法
  20. python中如何给散点图上面的特定点做标记

热门文章

  1. java 大数类_Java大数类介绍
  2. sat2 计算机科目,2019-2020年SAT2考试时间及Top100大学要求
  3. java多线程activemq,多线程JMS客户端ActiveMQ
  4. 尤克里里怎么样_尤克里里和吉他区别?尤克里里与吉他相比有什么不可替代的优势...
  5. 九个案例简述Web设计原则:简洁清晰
  6. Investigating Div-Sum Property【数位DP】
  7. topcoder srm 625 div1
  8. 加拿大大数据:正在升温的大数据市场
  9. centos6中三台物理机配置nginx+keepalived+lvs
  10. 团队项目—第二阶段第三天