New examples (#6242)

Adding new examples.
Improvement in existing method.
This commit is contained in:
rodolforfq 2019-01-30 11:40:24 -04:00 committed by Grzegorz Piwowarek
parent ef7bcbe669
commit f1ea814185
2 changed files with 14 additions and 1 deletions

View File

@ -5,6 +5,11 @@ public class Bicycle {
private String brand; private String brand;
private Integer frameSize; private Integer frameSize;
public Bicycle(String brand) {
this.brand = brand;
this.frameSize = 0;
}
public Bicycle(String brand, Integer frameSize) { public Bicycle(String brand, Integer frameSize) {
this.brand = brand; this.brand = brand;
this.frameSize = frameSize; this.frameSize = frameSize;

View File

@ -52,10 +52,18 @@ public class MethodReferenceExamples {
bikes.add(bikeCreatorMethodReference.apply("GT", 40)); 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 @Test
public void limitationsAndAdditionalExamples() { 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(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() { private List<Bicycle> createBicyclesList() {