Java 编译器 disable() 方法



描述

Java 编译器 disable() 方法导致编译器停止运行。

注意 - 此 API 自 Java 9 起已弃用,并且在 Java 21 及更高版本中不可用。

声明

以下是 java.lang.Compiler.disable() 方法的声明

public static void disable()

参数

返回值

此方法不返回值。

异常

启用和禁用编译器示例

以下示例演示了 java.lang.Compiler.disable() 方法的使用。在这个程序中,我们使用 enable() 方法启用了编译器。然后使用 command() 方法准备一个编译命令。然后我们检索了新创建的 Integer 对象的哈希码并打印了它。最后,我们使用 disable() 方法禁用了编译器。

package com.tutorialspoint;

public class CompilerDemo {

   public static void main(String[] args) {

      // checking if compiler is enabled or not        
      Compiler.enable();
      System.out.println("Compiler Enabled...");                          
      Compiler.command("{java.lang.Integer.*}(compile)");

      Integer i = new Integer("30");
    
      // returns a hash code value
      int retval = i.hashCode();
      System.out.println("Value = " + retval); 
 
      // disable the compiler
      System.out.println("Disabling Compiler..."); 
      Compiler.disable();                             
   }
} 

输出

让我们编译并运行上述程序,这将产生以下结果:

Compiler Enabled...
Value = 30
Disabling Compiler...
java_lang_compiler.htm
广告

© . All rights reserved.