New examples (#6242)
Adding new examples. Improvement in existing method.
This commit is contained in:
parent
ef7bcbe669
commit
f1ea814185
|
@ -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;
|
||||
|
|
|
@ -52,10 +52,18 @@ public class MethodReferenceExamples {
|
|||
bikes.add(bikeCreatorMethodReference.apply("GT", 40));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void referenceToConstructorSimpleExample() {
|
||||
List<String> 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<Bicycle> createBicyclesList() {
|
||||
|
|
Loading…
Reference in New Issue