[英]Exclude a particular method of a class from java compilation
I want to exclude a particular method of a class from java compilation. 我想从java编译中排除类的特定方法。
For eg: 例如:
class Test {
public void printdouble(){}
public void printint(){}
}
Depending upon some properties, I want to exclude printdouble
method during compilation. 根据某些属性,我想在编译期间排除
printdouble
方法。
NOTE: I'm using ant script for java compilation 注意:我正在使用ant脚本进行java编译
Thanks in Advance Soman 先谢谢Soman
You need to use a form of conditional compilation to achieve this. 您需要使用一种形式的条件编译来实现此目的。
Here's a tutorial on how to do it with Ant. 这是一个关于如何使用Ant 的教程 。
如果您解释为什么要尝试排除该方法,我们可能会提供一个更好的解决方案,不涉及预处理,代码生成和其他“hacky”方法。
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. 在Java中实现这一目标的唯一方法是生成源代码然后使用Ant编译的某种形式的代码生成或模板。
If you describe what you want to accomplish you may find a more "Java" way to accomplish it. 如果你描述了你想要实现的目标,你可能会找到一种更“Java”的方法来实现它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.