如果想得到具体的编译错误可以对Diagnostics进行扫描代码如下
for (Diagnostic diagnostic : diagnosticsgetDiagnostics())
Systemoutprintf(
Code: %s%n +
Kind: %s%n +
Position: %s%n +
Start Position: %s%n +
End Position: %s%n +
Source: %s%n +
Message: %s%n
diagnosticgetCode() diagnosticgetKind()
diagnosticgetPosition() diagnosticgetStartPosition()
diagnosticgetEndPosition() diagnosticgetSource()
diagnosticgetMessage(null));
被编译的testjava代码如下
public class test
{
public static void main(String[] args) throws Exception
{
aa; //错误语句
Systemoutprintln(JavaCompiler测试成功!);
}
}
在这段代码中多写了个aa得到的编译错误为
Code: compilererrnotstmt
Kind: ERROR
Position:
Start Position:
End Position:
Source: testjava
Message: testjava:: 不是语句
Success: false
[] [] [] []