mardi 12 mai 2015

Using reflection in java and ignoring NoClassDefFoundError/ClassNotFoundException

I have a class with methods that return a class only if that class exists, calling the method would generate a NoClassDefFoundError caused by ClassNotFoundException exception if the classpath is not loaded (rightfully so, because it's not mandatory).

How can I use Class#getMethods() when some of the methods (or fields) may not exist in the classpath? Is it possible to ignore the methods/fields when retrieving them?





Aucun commentaire:

Enregistrer un commentaire