Skip to content

Instantly share code, notes, and snippets.

@cky
Last active August 29, 2015 14:01
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 cky/b1c317164162bc2e5bf0 to your computer and use it in GitHub Desktop.
Save cky/b1c317164162bc2e5bf0 to your computer and use it in GitHub Desktop.
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);
}
}
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));
}
}
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