newInstance()在 java9中已被弃用

JAVA9之前用法

 Class.forName("类的全限定名").newInstance();

JAVA9之后用法

 Class.forName("类的全限定名").getDeclaredConstructor().newInstance();

源码说明

     /**
* Uses the constructor represented by this {@code Constructor} object to
* create and initialize a new instance of the constructor's
* declaring class, with the specified initialization parameters.
* Individual parameters are automatically unwrapped to match
* primitive formal parameters, and both primitive and reference
* parameters are subject to method invocation conversions as necessary.
*
* <p>If the number of formal parameters required by the underlying constructor
* is 0, the supplied {@code initargs} array may be of length 0 or null.
*
* <p>If the constructor's declaring class is an inner class in a
* non-static context, the first argument to the constructor needs
* to be the enclosing instance; see section 15.9.3 of
* <cite>The Java&trade; Language Specification</cite>.
*
* <p>If the required access and argument checks succeed and the
* instantiation will proceed, the constructor's declaring class
* is initialized if it has not already been initialized.
*
* <p>If the constructor completes normally, returns the newly
* created and initialized instance.
*
* @param initargs array of objects to be passed as arguments to
* the constructor call; values of primitive types are wrapped in
* a wrapper object of the appropriate type (e.g. a {@code float}
* in a {@link java.lang.Float Float})
*
* @return a new object created by calling the constructor
* this object represents
*
* @exception IllegalAccessException if this {@code Constructor} object
* is enforcing Java language access control and the underlying
* constructor is inaccessible.
* @exception IllegalArgumentException if the number of actual
* and formal parameters differ; if an unwrapping
* conversion for primitive arguments fails; or if,
* after possible unwrapping, a parameter value
* cannot be converted to the corresponding formal
* parameter type by a method invocation conversion; if
* this constructor pertains to an enum type.
* @exception InstantiationException if the class that declares the
* underlying constructor represents an abstract class.
* @exception InvocationTargetException if the underlying constructor
* throws an exception.
* @exception ExceptionInInitializerError if the initialization provoked
* by this method fails.
*/
@CallerSensitive
@ForceInline // to ensure Reflection.getCallerClass optimization
public T newInstance(Object ... initargs)
throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException
{
Class<?> caller = override ? null : Reflection.getCallerClass();
return newInstanceWithCaller(initargs, !override, caller);
}

The method newInstance() from the type Class is deprecated since version 9的更多相关文章

  1. The method buildSessionFactory() from the type Configuration is deprecated.SessionFactory的变化

    在创建Configuration对象之后:Configuration cfg = new Configuration().configure(); 要通过Configuration创建SessionF ...

  2. The method onClick(View) of type new View.OnClickListener(){} must override a superclass

    最近在做一个jWebSocket Android客户端的Demo时遇到如下错误: ok —————— 最近在做一个jWebSocket Android客户端的Demo时遇到如下错误: ".. ...

  3. eclise -The method onClick(View) of type new View.OnClickListener(){} must override a superclass method

    在做arcgis android开发的时候,突然遇到这种错误,The method onClick(View) of type new View.OnClickListener(){} must ov ...

  4. Bean property ‘mapperHelper’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

    spring boot 报错: Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property ...

  5. JAVA克隆对象报错:The method clone() from the type Object is not visible

    将一个对象复制一份,称为对象的克隆技术.在Object类汇总存在一个clone()方法:protected Onject clone() throws CloneNotSupportedExcepti ...

  6. eclise -The method onClick(View) of type new View.OnClickListener(){} must override a superclass method 在做arcgis android开发的时候,突然遇到这种错误,The method onClick(View) of type new View.OnClickListener(){} mus

    eclise -The method onClick(View) of type new View.OnClickListener(){} must override a superclass met ...

  7. No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty planning

    No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty plann ...

  8. IDEA Method definition shorthands are not supported by current JavaScript version

    sentinel-dashboard前端用到了AngularJS v1.4.8,在IDEA里修改js,触发js验证时有一些js文件会出现红色波浪线. 在代码行里鼠标一上去提示信息:Method def ...

  9. 报错:Method definition shorthands are not supported by current JavaScript version

    当你在html中使用调用js中的方法时,会出现这行报错: method definition shorthands are not supported by current JavaScript ve ...

随机推荐

  1. Spring Cloud(一):入门篇

    Spring Cloud 简介 Spring Cloud 是一个基于 Spring Boot 实现的微服务架构开发工具,可以快速构建分布式系统中的某些常用模式,如配置管理.服务治理.断路器.智能路由. ...

  2. Spring Boot 2 快速教程:WebFlux 快速入门(二)

    摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘要,谢谢! 02:WebFlux 快速入门实践 文章工程: JDK 1.8 ...

  3. cmdb项目-1

    1.什么是cmdb 配置管理数据库 ,存储基础设备的各种信息配置等 CMDB可以存储并自动发现整个IT网络上的各种信息,比如一个IT网络上有多少台服务器.多少存储.设备的品牌.资产编号.维护人员.所属 ...

  4. CICD-Jenkins笔记2014-2018

    CICD-Jenkins笔记2014-2018 20141119 chenxin 20180726 chenxin update 四个环境,开发/测试/预发布/生产. 文中涉及的最新脚本,请查看西部战 ...

  5. Saltstack_使用指南18_API

    1. 主机规划 salt 版本 [root@salt100 ~]# salt --version salt (Oxygen) [root@salt100 ~]# salt-minion --versi ...

  6. 并发编程~~~多线程~~~守护线程, 互斥锁, 死锁现象与递归锁, 信号量 (Semaphore), GIL全局解释器锁

    一 守护线程 from threading import Thread import time def foo(): print(123) time.sleep(1) print('end123') ...

  7. Python安装常见问题(1):zipimport.ZipImportError: can't decompress data(此问题不解决pip安装不成功)

    在CentOS以及其他的Linux系统中遇到安装包安装错误的原因,大多数都是因为缺少依赖包导致的,所以对于错误:zipimport.ZipImportError: can’t decompress d ...

  8. MySql 表结构修改、约束条件、表关系

    表结构修改(alter) 查看表的结构:desc 表名; 修改表名:alter table 表名 rename to 新表名; 修改字段名:alter table 表名 change 旧字段名 新字段 ...

  9. z390 m.2 接口插上sata 硬盘后,机械硬盘不识别;HDD 硬盘不识别;z390 m.2和 SATA 硬盘安装组合;

    今天,在集成z390芯片组的主板上,安装了一块m.2支持 sata协议的ssd时,发现安装上ssd后,之前机械硬盘不识别了:还以为机械硬盘烧了: 在网上查找相关博客可以发现,是M.2 SATA 和 S ...

  10. 一个驱动导致的内存泄漏问题的分析过程(meminfo->pmap->slabtop->alloc_calls)

    关键词:sqllite.meminfo.slabinfo.alloc_calls.nand.SUnreclaim等等. 下面记录一个由于驱动导致的内存泄漏问题分析过程. 首先介绍问题背景,在一款嵌入式 ...