Skip to content

Instantly share code, notes, and snippets.

@brunoborges
Created May 5, 2014 00:49
Show Gist options
  • Save brunoborges/67d6195bbe76f6d68b00 to your computer and use it in GitHub Desktop.
Save brunoborges/67d6195bbe76f6d68b00 to your computer and use it in GitHub Desktop.
JDK 8 compiler fails if referenced final variable is not being called with "this."
/**
* @author bruno.borges@oracle.com
*/
public class FooBar {
private final String foobar;
public FooBar() {
foobar = "foobar";
}
private final java.util.function.Function ds = n -> {
System.out.println(this.foobar); // compiles successfuly
System.out.println(foobar); // throws compilation error: "variable foobar might not have been initialized"
return foobar;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment