Samples JDK
Test1.java
1 package com.freemindcafe.java8.sample1;
2 
3 import java.util.Optional;
4 
5 import org.junit.Test;
6 
7 public class Test1{
8 
9  @Test(expected=NullPointerException.class)
10  public void should_throw_null_pointer_exception(){
11  System.out.println(new Person().car.insurance.name);
12  }
13 
14  @Test
15  public void should_not_throw_null_pointer_exception(){
16  //System.out.println(new Person().optionalCar.map((c) -> c.optionalInsurance).map((i) -> i.);
17  }
18 
19 }
20 
21 class Person {
22  Car car;
23  Optional<Car> optionalCar;
24 }
25 
26 class Car{
27  Insurance insurance;
28  Optional<Insurance> optionalInsurance;
29 }
30 
31 class Insurance{
32  String name;
33 }