Eclipse EcLemma 涵盖的指令数多于代码行数

Eclipse EcLemma number of covered instructions more than lines of code

在覆盖结果中,它显示我覆盖了 9 条指令,而只有 5 行以绿色突出显示。其他 4 条指令是哪些?

正如@schmosel 所说,它正在计算字节码指令。

您可以通过阅读 EMMA reference documentation(EclEMMA 是围绕 EMMA 的 Eclipse GUI)来验证这一点,其中始终使用短语 "bytecode instructions"。

单击覆盖范围框右上角的下拉箭头。它会给你一个couple different ways to measure your coverage。默认好像是instructions(字节码指令),不过你可以手动select行。

您看到 9 条指令的原因是 Foo 中有 9 条字节码指令:

$ javap -c Foo.class 
Compiled from "Foo.java"
public class Foo {
  public Foo();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: getstatic     #16                 // Field java/lang/System.out:Ljava/io/PrintStream;
       3: ldc           #22                 // String Test
       5: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8: new           #1                  // class Foo
      11: invokespecial #30                 // Method "<init>":()V
      14: return
}