Last active
August 29, 2015 14:17
-
-
Save marsyang1/679a79dbf1cf96a473ba to your computer and use it in GitHub Desktop.
Java Lambda test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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