Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevenschwenke/f7470fc434e3d334436d2c22f05d7f17 to your computer and use it in GitHub Desktop.
Save stevenschwenke/f7470fc434e3d334436d2c22f05d7f17 to your computer and use it in GitHub Desktop.
@FunctionalInterface
public interface SimpleFunctionalInterface {
public int returnAnswerToUltimateQuestion();
}
@Test
public void normalInterfaceOnlyOneAbstractMethod() {
int x = 1;
SimpleFunctionalInterface myInterfaceImpl = () -> {
// x = 2; // impossible
instanz = 3; // possible because member variables are copied when creating lambdas. (http://stackoverflow.com/questions/25055392/lambdas-local-variables-need-final-instance-variables-dont)
// TODO: Why is the class, in which the lambda is defined, copied? I thought that lambdas are "closed" definitions of functionality that can be passed around.
return 0;
};
}
@stevenschwenke
Copy link
Author

Thanks a lot! Changed my workshop accordingly. Could you please have a look at this commit? It should contain everything important, but a review would be nice. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment