简体   繁体   English

从java编译中排除类的特定方法

[英]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.

相关问题 是否有一个被认为与任何特定类分开的java方法的名称? - Is there a name for a java method considered as separate from any particular class? 参数化 java class 方法未解决的编译问题 - Unresolved compilation problem for parameterized java class method 如何检查java类中是否有特定的方法? - How to check if a java class has a particular method in it? 从另一个特定类访问类方法 - Access a Class method from another particular class Selenium Webdriver(Java)-从CSS选择器中排除特定标签 - Selenium Webdriver (Java) - exclude a particular tag from the css selector Java:实例化抽象类的特定子类的方法 - Java: Method to instantiate a particular sub class of an abstract class 从Java中的子类访问受保护的方法时,为什么会出现编译错误? - Why is there a compilation error when accessing protected method from subclass in Java? 如何仅允许特定成员访问类 java 中的方法 - How to allow accessing to a method in a class java only to particular members Java中的条件编译:编译器会从类中省略“always false”块吗? - Conditional compilation in Java: will compiler omit “always false” blocks from class? 锁定Java中的特定方法 - Lock a particular method in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM