There is no guarantee that the JVM will load all classes from the .jar file into memory, although it may preload part or all of the .jar as an optimization.
If this fails, and I believe that at some point this will not happen in the middle of the method. This would be at the point where the new class should be loaded from the class path, and the JVM would no longer be able to access this file. Then you fail with NoClassDefFoundError or worse.
So no, I would definitely not advise you to do this, even if this happens in some cases.
source share