Skip to content

Instantly share code, notes, and snippets.

@marsyang1
Last active August 29, 2015 14:17
Show Gist options
  • Save marsyang1/679a79dbf1cf96a473ba to your computer and use it in GitHub Desktop.
Save marsyang1/679a79dbf1cf96a473ba to your computer and use it in GitHub Desktop.
Java Lambda test
@Slf4j
public class JavaLambdaTest {
public static void main(String[] args) {
log.info("Hello");
testNoArgsLambda();
testWithArgsLambda();
}
private static void testNoArgsLambda() {
Runnable task = () -> {
log.info("runable get run");
};
Runnable task2 = () -> log.info("runable get run");
task.run();
task2.run();
}
private static void testWithArgsLambda() {
BinaryOperator<Long> add = (Long x, Long y) -> x + y;
BinaryOperator<Long> sub = getSub();
log.info("add Lambda apply (1L,2L) = " + add.apply(1L, 2L));
log.info("sub Lambda apply (1L,2L) = " + sub.apply(1L, 2L));
}
private static BinaryOperator<Long> getSub() {
return (Long x, Long y) -> x - y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment