當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.lang.Compiler.command()用法及代碼示例


描述

這個java.lang.Compiler.command() 方法檢查參數類型及其字段並執行一些記錄的操作。

聲明

以下是聲明java.lang.Compiler.command()方法

public static boolean command(Object arg)

參數

Object arg- compiler-specific 參數

返回值

此方法返回 compiler-specific 值,包括空值。

異常

NullPointerException- 如果編譯器不喜歡空參數。

示例

下麵的例子展示了 java.lang.Compiler.command() 方法的用法。

package com.tutorialspoint;

import java.lang.*;

public class CompilerDemo {

   public static void main(String[] args) {

      CompilerDemo cls = new CompilerDemo();
      CompilerDemo subcls = new SubClass1();

      // class CompilerDemo
      Class c = cls.getClass(); 
      System.out.println(c);

      // sub class SubClass1
      Class c1 = subcls.getClass();
      System.out.println(c1);

      /* Let's compile CompilerDemo class using command method */
      Object retval = Compiler.command("javac CompilerDemo");

      System.out.println("Return Value = " + retval); 
   }
} 

class SubClass1 extends CompilerDemo {
   // sub class
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

class com.tutorialspoint.CompilerDemo
class com.tutorialspoint.SubClass1
Return Value = null

相關用法


注:本文由純淨天空篩選整理自 Java.lang.Compiler.command() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。