The following code produces an NPE in JLang code when accessing s.length.
If s is not final then this is an NPE in both JDK and JLang.
However, making sfinal causes this code to succeed in JDK but still produces an NPE in JLang.
private static final int a = calculate();private static final String s = "my string3";private static int calculate() { return s.length();}
Specifically the issue is with "constant variables" see: jlr
This also applies to ints:
private static final int a = calculate();private static final int b = 3;private static int calculate() { return b;}
After this code, a is set to 0, not 3 in JLang, since b is not initialized at compile time properly.
The following code produces an NPE in JLang code when accessing s.length. If
s
is notfinal
then this is an NPE in both JDK and JLang. However, makings
final
causes this code to succeed in JDK but still produces an NPE in JLang.private static final int a = calculate();
private static final String s = "my string3";
private static int calculate() { return s.length();}
Specifically the issue is with "constant variables" see: jlr
This also applies to ints:
private static final int a = calculate();
private static final int b = 3;
private static int calculate() { return b;}
After this code,
a
is set to 0, not 3 in JLang, sinceb
is not initialized at compile time properly.