mardi 14 septembre 2021

How to make reflection work on JDK 16 and later?

I have the following legacy code that I migrated to Java 16 but that doesn't work:

try {
    Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
    method.setAccessible(true);
    method.invoke(URLClassLoader.getSystemClassLoader(), file.toURI().toURL());
} catch (Exception e) {
    e.printStackTrace();
}

... Is there a way to make it works?





Aucun commentaire:

Enregistrer un commentaire