Is there something like #ifdef for methods in java?
Is there something in java that would allow me to stop a method from compiling into a program depending on the value? Something like:
#ifdef CLIENT
public void drawToScreen() {
}
#endif
#ifdef SERVER
public void sendPacketToClient() {
}
#endif
If you had two versions of the program, one client and one server, how could you do this? Is there a way to do this with classes as well?
source to share
Not very easy. All other comments say that this is not possible, but in fact it is possible
If you really wanted to, you can use the bytecode manipulation library . As the JavaAssist site says:
Javassist (Java Programming Assistant) makes Java bytecode manipulation easy. It is a class library for editing bytecode in Java; it allows Java programs to define a new class at runtime and modify the class file when the JVM loads it.
But the biggest question is, what's the point? This is really too much work and not very useful.
source to share