Skip to content

Instantly share code, notes, and snippets.

@bryder
Last active January 9, 2017 03:29
Show Gist options
  • Save bryder/b321152c20ba6d9aa678b18ea35f6708 to your computer and use it in GitHub Desktop.
Save bryder/b321152c20ba6d9aa678b18ea35f6708 to your computer and use it in GitHub Desktop.
How to define an interface and use it for a lamba
private interface NameOfInterface {
public List getAList(Object anArgument);
}
public void useThePassedMethod(NameOfInterface thingToRun) {
Integer thing = 1;
List createdList = thingToRun.getAList(thing);
}
public void callTheThingUsingTheInterface(){
// WIth a static method which meets the specs for a lamdba
useThePassedMethod(ClassWithMethodMatchingInterface::methodName);
// WIth a lambda
useThePassedMethod((anArgument) -> {
return new ArrayList(anArgument);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment