[BUG] Missing error? blank final may not have been initialized
Raffaele Sgarro
raffaelesgarro at gmail.com
Mon Apr 7 17:02:28 UTC 2014
§16 states:
For every access of a local variable or blank final field x, x must be
definitely assigned before the access, or a compile-time error occurs.
Such an assignment is defined to occur if and only if either the simple
name of the variable (or, for a field, its simple name qualified by this)
occurs on the left hand side of an assignment operator.
Consider the following code:
class Ideone {
public interface Provider { String get(); }
public static class Outer {
private final String data;
private final String token;
private final Provider secretProvider = new Provider() {
public String get() {
return data;
}
};
public Outer() {
token = secretProvider.get();
data = "FOOBAR";
}
public String getToken() {
return token;
}
}
public static void main (String[] args) throws java.lang.Exception {
Outer outer = new Outer();
System.out.println(outer.getToken()); // Prints null
}}
Note that if I used a lambda expression, instead, javac would have
complained.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140407/da10c610/attachment.html>
More information about the compiler-dev
mailing list