Java类类getConstructor()方法及示例

类的类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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545276.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

where、having、group by、order by、count的使用注意

where、having、group by、order by、count的使用注意1_where、having、group by、order by的顺序2_group by的作用3_where和group by的组合4_group by和having的组合5_where、having、group by的组合使用6_count与group by的组合使用1_where、having、group by、order by的顺序…

Oracle备份还原

Oracle有两类备份方式: (1)物理备份:是将实际组成数据库的操作系统文件从一处拷贝到另一处的备份过程,通常是从磁盘到磁带。物理备份又分为冷备份、热备份; (2)逻辑备份&#xff1…

Eclipse快捷键-方便查找

【Ct rlT】 搜索当前接口的实现类 1. 【ALT /】 此快捷键为用户编辑的好帮手,能为用户提供内容的辅助,不要为记不全方法和属性名称犯愁,当记不全类、方法和属性的名字时,多体验一下【ALT /】快捷键带来的好处吧。 2. 【Ct rlO】…

很实用的21个SQL小技巧!

前言每一个好习惯都是一笔财富,本文基于MySQL,分SQL后悔药, SQL性能优化,SQL规范优雅三个方向,分享写SQL的21个好习惯,谢谢阅读,加油哈~1. 写完SQL先explain查看执行计划(SQL性能优化…

Java ByteArrayOutputStream size()方法与示例

ByteArrayOutputStream类size()方法 (ByteArrayOutputStream Class size() method) size() method is available in java.io package. size()方法在java.io包中可用。 size() method is used to return the current size of the buffer exists. size()方法用于返回缓冲区当前存…

Oracle备份文件名获取系统时间的做法(windows)

在对数据库进行备份时,用数据泵的方法,需要执行一段代码: --建目录 create directory dir as d:\bak;--给用户授权使用目录 grant read,write on directory dir to scott;--在cmd中输入以下代码 expdp scott/tigerXE directorydir dumpfileab…

java getmonth_Java LocalDateTime类| 带示例的getMonth()方法

java getmonthLocalDateTime类getMonth()方法 (LocalDateTime Class getMonth() method) getMonth() method is available in java.time package. getMonth()方法在java.time包中可用。 getMonth() method is used to get the field value month-of-year based on the enum Mon…

阿里最喜欢问的多线程顺序打印的5种解法!

Keeper导读大家在换工作面试中,除了一些常规算法题,还会遇到各种需要手写的题目,所以打算总结出来,给大家个参考。全文 2929 字,剩下的是代码,P6 及以下阅读只需要 8 分钟,高 P 请直接关闭第一篇…

CSS入门

CSS入门1_CSS概要1.1_CSS引入方式2_CSS选择器3_字体样式3.1_字体属性3.2_字体类型:font-family3.3_字体大小:font-size3.4_字体粗细:font-weight3.5_字体颜色:color3.6_总结4_文本样式4.1_文本样式属性4.2_首行缩进:te…

Oracle笔记:数据库启动的三个阶段

数据库的启动可分为三个阶段:1、startup nomount -- 启动实例,不加载数据库 nomount:在这一阶段,只需要读取initSID.ora文件,启动数据库实例,创建后台进程。在initSID.ora文件中,可以定位…

Java LocalDate类| lengthOfYear()方法和示例

LocalDate类lengthOfYear()方法 (LocalDate Class lengthOfYear() method) lengthOfYear() method is available in java.time package. lengthOfYear()方法在java.time包中可用。 lengthOfYear() method is used to get the length of the year represented by this LocalDate…

23张图!万字详解「链表」,从小白到大佬!

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)链表和数组是数据类型中两个重要又常用的基础数据类型。数组是连续存储在内存中的数据结构,因此它的优势是可以通…

何为“秒传”

写在前面 最近一直在弄文件传输的组件,在讨论组里面,有同事提到“秒传”的功能。在目前的通信软件中也有网盘的功能,就从网上搜了一下,这里对“秒传”的实现思路做一下总结,在之后会写一个小的demo实现一下。没有其他&…

JavaScript入门

JavaScript入门1_语法基础1.1_变量1.2_数据类型1.3_运算符1.4_类型转换1.5_注释跟c一样2_流程控制语句3_函数3.1_没有返回值的函数3.2_有返回值的函数4_对象4.1_对象简介4.2_字符串对象4.3_数组对象4.4_时间对象4.5_数学对象简介5_DOM基础5.1_DOM是什么5.2_节点类型5.3_获取元素…

oracle 序列的概念与使用步骤

转载自:http://www.worlduc.com/blog2012.aspx?bid20342458 一、概念 1、 序列: 是oacle提供的用于产生一系列唯一数字的数据库对象。主要用于提供主键值。 2、 创建序列: 创建序列的语法 CREATE SEQUENCE sequence //创建序列名称 [INCREMENT BY n]…

数组转List的3种方法和使用对比!

作者 | 大脑补丁来源 | blog.csdn.net/x541211190/article/details/79597236前言:本文介绍Java中数组转为List三种情况的优劣对比,以及应用场景的对比,以及程序员常犯的类型转换错误原因解析。一.最常见方式(未必最佳)…

java 根据类名示例化类_Java即时类| getEpochSecond()方法与示例

java 根据类名示例化类即时类getEpochSecond()方法 (Instant Class getEpochSecond() method) getEpochSecond() method is available in java.time package. getEpochSecond()方法在java.time包中可用。 getEpochSecond() method is used to get the number of seconds from t…

oracle10g备份导入

2019独角兽企业重金招聘Python工程师标准>>> //导出 exp test/testgdsoft filed:\gd.dmp //删用户 drop user wkwx cascade; //用PLSQL创建数据数据库 create user hzjzjn identified by hzjzjn default tablespace BDP_DATABD; grant CREATE USER,DROP USER,ALTE…

VisualSVNServer的使用

VisualSVNServer的使用1_服务端初识1.1_创建新仓库1.2_创建用户并分配权限1_服务端初识 1.1_创建新仓库 右击Repository,点击create 点击下一步 输入仓库名 右击空白处,点击新建,点击project structure 输入工程名 1.2_创建用户并分…

安利一个IDEA骚操作:一键生成方法的序列图

在平时的学习/工作中,我们会经常面临如下场景:阅读别人的代码阅读框架源码阅读自己很久之前写的代码。千万不要觉得工作就是单纯写代码,实际工作中,你会发现你的大部分时间实际都花在了阅读和理解已有代码上。为了能够更快更清晰地…