[英]Dynamic class loading (java 11)
I have the following code我有以下代码
ClassLoader classLoader = IFileTransferClient.class.getClassLoader();
Class f_t_c = classLoader.loadClass(fileGroupConfig.getFileTransferClientClassName());
fileTransferClient = (IFileTransferClient) f_t_c.newInstance();
The compiler (Java 11) is complaining that newInstance
is deprecated.编译器 (Java 11) 抱怨
newInstance
已被弃用。
How does one convert the above code for Java 11 compiler?如何将上述代码转换为 Java 11 编译器?
It is a long standing deprecation of Class#newInstance
.这是
Class#newInstance
长期弃用。
f_t_c.getConstructor().newInstance();
The call above will invoke the normal (in this case: default) constructor, which allows all handling on construction, like exceptions.上面的调用将调用普通(在这种情况下:默认)构造函数,它允许对构造进行所有处理,如异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.