【问题标题】:Not compiling parts of the code in java(like #ifdef) [duplicate]不在java中编译部分代码(如#ifdef)[重复]
【发布时间】:2014-01-15 05:02:25
【问题描述】:

我希望有可能不编译我的部分 JAVA 代码。有时...

我想念我在 c++ 中使用的编译器指令的可能性

#ifdef DEBUG
 println("debug messae);
#endif

在java中我们没有这种可能性。

我想知道是否有一个外部工具,某种 Java 预编译器,可以让我灵活地使用 Java 代码执行此操作。

谢谢你, 吉拉德

【问题讨论】:

  • 您可以为此使用记录器。可以通过配置文件指定错误、调试等启用的级别。
  • @AniketThakur 我根本不希望将此代码合并到字节码中...

标签: java compiler-construction annotations


【解决方案1】:

static final booleans 可用于在编译时消除if statements 内的代码。例如

private static final boolean check= false;    

if (check) {
  // This is removed at compile time
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多