Javap missing some line numbers?

if I compile the following source code:

1.  public class Example {
2.    public boolean foo(boolean a, boolean b, char ch) {
3.      if (a && Character.isLetter(ch)
4.            || b && Character.isDigit(ch)
5.            || !a && !b) {
6.        return true;
7.      }
8.      return false;
9.    }
10. }

with Java-7 (OpenJDK or Oracle), I get the following LineNumberTable:

line 3: 0
line 6: 30
line 8: 32

however, compiling the same source code with Java-8 (OpenJDK or Oracle), I get another LineNumberTable:

line 3: 0
line 4: 16
line 6: 30
line 8: 32

Why does the LineNumberTable returned by Java-7 not include lines 4 and 5? and why does the LineNumberTable returned by Java-8 not include line 5?

Thanks,

+4
source share
1 answer

, , . . . , , , .

javac . Eclipse, , . , , .

-, , , . , , .

, , . ,

static int test(int a, int b, int c, int d) {
    return
            a
           +b
           +c
           +d;
}

, return.

static int test(int a, int b, int c, int d) {
    return
            a
           +b
           +c+test(a,b,c,d)
           +d;
}

, return . , .

static int test(int a, int b, int c, int d) {
    return
            a
           +b+test(a,b,c,d)
           +c
           +d+test(a,b,c,d);
}

javac.

+3

Source: https://habr.com/ru/post/1625325/


All Articles