Last active
August 29, 2015 14:01
-
-
Save cky/b1c317164162bc2e5bf0 to your computer and use it in GitHub Desktop.
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
import java.util.Arrays; | |
/** | |
* Demonstration of bound method references. | |
*/ | |
public class MethodReferenceExample1 { | |
public static void main(String[] args) { | |
Arrays.stream(args, 1, args.length).filter(args[0]::contains) | |
.forEach(System.out::println); | |
} | |
} |
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
import java.math.BigDecimal; | |
import java.util.Arrays; | |
/** | |
* Demonstration of constructor and unbound method references. | |
*/ | |
public class MethodReferenceExample2 { | |
public static void main(String[] args) { | |
System.out.println(Arrays.stream(args).map(BigDecimal::new) | |
.reduce(BigDecimal.ZERO, BigDecimal::add)); | |
} | |
} |
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
import java.util.Arrays; | |
/** | |
* Demonstration of static method references, and a simple lambda. | |
*/ | |
public class MethodReferenceExample3 { | |
public static void main(String[] args) { | |
System.out.println(Math.sqrt(Arrays.stream(args) | |
.mapToDouble(Double::parseDouble).map(x -> x * x).sum())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment