Skip to content

Commit f1ea814

Browse files
rodolforfqpivovarit
authored andcommitted
New examples (eugenp#6242)
Adding new examples. Improvement in existing method.
1 parent ef7bcbe commit f1ea814

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ public class Bicycle {
55
private String brand;
66
private Integer frameSize;
77

8+
public Bicycle(String brand) {
9+
this.brand = brand;
10+
this.frameSize = 0;
11+
}
12+
813
public Bicycle(String brand, Integer frameSize) {
914
this.brand = brand;
1015
this.frameSize = frameSize;

‎core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceExamples.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ public void referenceToConstructor() {
5252
bikes.add(bikeCreatorMethodReference.apply("GT", 40));
5353
}
5454

55+
@Test
56+
public void referenceToConstructorSimpleExample() {
57+
List<String> bikeBrands = Arrays.asList("Giant", "Scott", "Trek", "GT");
58+
bikeBrands.stream()
59+
.map(Bicycle::new)
60+
.toArray(Bicycle[]::new);
61+
}
62+
5563
@Test
5664
public void limitationsAndAdditionalExamples() {
5765
createBicyclesList().forEach(b -> System.out.printf("Bike brand is '%s' and frame size is '%d'%n", b.getBrand(), b.getFrameSize()));
58-
createBicyclesList().forEach((o) -> this.doNothingAtAll(o));
66+
createBicyclesList().forEach((o) -> MethodReferenceExamples.doNothingAtAll(o));
5967
}
6068

6169
private List<Bicycle> createBicyclesList() {

0 commit comments

Comments
 (0)