Skip to content

Instantly share code, notes, and snippets.

@viniciusd
Last active July 26, 2019 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniciusd/65658d7635aead8de825ce641ce1c832 to your computer and use it in GitHub Desktop.
Save viniciusd/65658d7635aead8de825ce641ce1c832 to your computer and use it in GitHub Desktop.
import java.util.function.Function;
public class MyClass {
private static Function<Integer,Integer> outside(Integer y) {
return new Function<Integer, Integer>() {
@Override
public Integer apply(Integer x) {
return x + y;
}
};
}
private static Function<Integer,Integer> outside_lambda(Integer y) {
return (x) -> (y + x);
}
public static void main(String args[]) {
int x=10;
int y=25;
Function<Integer,Integer> inner_fn = outside(new Integer(y));
int z = inner_fn.apply(x).intValue();
System.out.println("Sum of x+y = " + z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment