I need help trying to understand why this is happening to me:
Using Java 1.8.0_131 , I have a class, for example:
public class DynamicClassLoadingAppKO {
private static void showMessage(final ParentClassFromLibOne obj) {
System.out.println(obj.message());
}
public static void main(final String[] args) throws Throwable {
try {
final ChildClassFromLibTwo obj = new ChildClassFromLibTwo();
showMessage(obj);
} catch (final Throwable ignored) {
}
System.out.println("This should be displayed, but no :(");
}
}
Two other classes are used there: ParentClassFromLibOneand ChildClassFromLibTwo. The latter extends from the first.
There are two external libraries:
- One library is called
liboneand contains a class ParentClassFromLibOne. The application includes this library in the class path for both compilation and execution. - The second library is called
libtwoand contains the class ChildClassFromLibTwo. The application includes this library in the classpath for compilation , but not for execution .
, Java ChildClassFromLibTwo ( ):
final ChildClassFromLibTwo obj = new ChildClassFromLibTwo();
, , ClassNotFoundException, try...catch (Throwable), System.out.println .
, ClassNotFoundException, DynamicClassLoadingAppKO, , main() , try...catch.
, , , , , showMessage(), :
private static void showMessage(final ChildClassFromLibTwo obj) {
System.out.println(obj.message());
}
? , ?
GitHub, [1].
[1] https://github.com/danielfernandez/test-dynamic-class-loading/tree/20170504