Java 編譯器 enable() 方法



描述

Java 編譯器 enable() 方法使編譯器恢復執行。

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

宣告

以下是 java.lang.Compiler.enable() 方法的宣告

public static void enable()

引數

返回值

此方法不返回任何值。

異常

啟用編譯器示例

以下示例顯示了 java.lang.Compiler.enable() 方法的使用。在此程式中,我們使用 enable() 方法啟用了編譯器。然後使用 command() 方法準備編譯命令。然後,我們檢索了新建立的 Integer 物件的雜湊碼並列印了它。

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("50");
    
      // returns a hash code value
      int retval = i.hashCode();
      System.out.println("Value = " + retval); 
   }
} 

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Compiler Enabled...
Value = 50
java_lang_compiler.htm
廣告

© . All rights reserved.