tags:

views:

64

answers:

3

Hi,

I want to exclude a particular method of a class from java compilation.

For eg:

class Test { 
       public void printdouble(){}
       public void printint(){}
 }

Depending upon some properties, I want to exclude printdouble method during compilation.

NOTE: I'm using ant script for java compilation

Thanks in Advance Soman

+1  A: 

The only way to accomplish that in Java is some form of code generation or templating that generates the source code and then has Ant compile that.

If you describe what you want to accomplish you may find a more "Java" way to accomplish it.

Yishai
+3  A: 

You need to use a form of conditional compilation to achieve this.

Here's a tutorial on how to do it with Ant.

Lucero
Thanks, it works fine
Soman
+1  A: 

If you explain why you are trying to exclude the method, we can probably offer a better solution that does not involve preprocessing, code generation and other "hacky" approaches.

Stephen C