Java-lang-compiler-command

提供:Dev Guides
移動先:案内検索

Java.lang.Compiler.command()メソッド

説明

  • java.lang.Compiler.command()*メソッドは、引数の型とそのフィールドを調べ、文書化された操作を実行します。

宣言

以下は* java.lang.Compiler.command()*メソッドの宣言です

public static boolean command(Object arg)

パラメーター

*Object arg* -コンパイラ固有の引数

戻り値

このメソッドは、nullを含むコンパイラ固有の値を返します。

例外

*NullPointerException* -コンパイラがnull引数を好まない場合。

次の例は、java.lang.Compiler.command()メソッドの使用法を示しています。

package com.finddevguides;

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.finddevguides.CompilerDemo
class com.finddevguides.SubClass1
Return Value = null