Can I import the cause of the crash / error after compilation?

As in the title.

Example: I have a program with 3 classes: Server, Client, Main.

Main has 2 imports - server and client. Depending on which mode I run the program in (client or server), the main class will use the method from this class.

Now let's say I remove Server.class from .jar - will the program crash if I run it in client mode? I am not using any methods from the remote class (it is blocked by if (...), there is only its import and the unused reference is blocked by if ofc.

+3


source to share


1 answer


If the program never reaches the part that the server class uses when it is run in "client mode", the program will generally work fine without crashing because the JVM will only load the class file when using the class.



However, once the server class is referenced in any other state, the program will crash with NoClassDefFoundError

, so this solution imposes risks.

+3


source







All Articles