Issue
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.
How does one convert the above code for Java 11 compiler?
Solution
It is a long standing deprecation of 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.
Answered By - Joop Eggen
Answer Checked By - Clifford M. (JavaFixing Volunteer)