java非静态内部类getConstructor抛出异常问题

在尝试使用java.lang.Class.getConstructor方法获取非静态内部类的构造器时,遇到了NoSuchMethodException。注释表明,对于非静态内部类,需要提供外部类类型作为参数,而非内部类本身。通过示例代码展示正确调用方式,即传入外部类类型,否则会抛出异常。要完全理解这一行为的实现原理,需要进一步阅读源代码。
摘要由CSDN通过智能技术生成

           最近遇到一个问题,java非静态的内部类,在调用到java.lang.Class.getConstructor(Class<?>...)这个方法时,抛出了异常NoSuchMethodException,这是为什么呢?

          仔细看java.lang.Class.getConstructor(Class<?>...)这个方法的注释,如下:

 

    /**
     * Returns a <code>Constructor</code> object that reflects the specified
     * public constructor of the class represented by this <code>Class</code>
     * object. The <code>parameterTypes</code> parameter is an array of
     * <code>Class</code> objects that identify the constructor's formal
     * parameter types, in declared order.  
     *
     * If this <code>Class</code> object represents an inner class
     * declared in a non-static context, the formal parameter types
     * include the explicit enclosing instance as the first par
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值