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.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

