jeudi 25 avril 2019

Is it possible to determine if a class has been loaded without loading it?

This question from 10 years ago (wow!) asks about how to check if a Java class has been loaded without loading the class if it has not been loaded. The accepted answer of using ClassLoader#findLoadedClass via reflection has worked well for me.

However, now that I've updated to Java 11, the system complains about illegal access, stating that the operation will be denied in future releases.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by foo.Bar(file:/F:/Foo/bin/) to method java.lang.ClassLoader.findLoadedClass(java.lang.String)
WARNING: Please consider reporting this to the maintainers of foo.Bar
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Is there any other way in Java to check if a class has been loaded without loading it?





Aucun commentaire:

Enregistrer un commentaire