From f1ea814185be1e0bf555bb49c737da27eed86b3f Mon Sep 17 00:00:00 2001 From: rodolforfq <31481067+rodolforfq@users.noreply.github.com> Date: Wed, 30 Jan 2019 11:40:24 -0400 Subject: [PATCH] New examples (#6242) Adding new examples. Improvement in existing method. --- .../baeldung/java8/lambda/methodreference/Bicycle.java | 5 +++++ .../methodreference/MethodReferenceExamples.java | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java b/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java index 760a24d7c2..26f9f8bc46 100644 --- a/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java +++ b/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java @@ -5,6 +5,11 @@ public class Bicycle { private String brand; private Integer frameSize; + public Bicycle(String brand) { + this.brand = brand; + this.frameSize = 0; + } + public Bicycle(String brand, Integer frameSize) { this.brand = brand; this.frameSize = frameSize; diff --git a/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceExamples.java b/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceExamples.java index 3b9a5ec6ff..ede0ef9f70 100644 --- a/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceExamples.java +++ b/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceExamples.java @@ -52,10 +52,18 @@ public class MethodReferenceExamples { bikes.add(bikeCreatorMethodReference.apply("GT", 40)); } + @Test + public void referenceToConstructorSimpleExample() { + List bikeBrands = Arrays.asList("Giant", "Scott", "Trek", "GT"); + bikeBrands.stream() + .map(Bicycle::new) + .toArray(Bicycle[]::new); + } + @Test public void limitationsAndAdditionalExamples() { createBicyclesList().forEach(b -> System.out.printf("Bike brand is '%s' and frame size is '%d'%n", b.getBrand(), b.getFrameSize())); - createBicyclesList().forEach((o) -> this.doNothingAtAll(o)); + createBicyclesList().forEach((o) -> MethodReferenceExamples.doNothingAtAll(o)); } private List createBicyclesList() {