Created
November 16, 2015 14:06
-
-
Save ivanursul/82bcb67bc7fbe7daa02f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Insurance insurance = new Insurance("insurance1"); | |
Car car = new Car(Optional.of(insurance)); | |
Person person = new Person(Optional.of(car)); | |
Optional<String> s = person.getCar() | |
.flatMap(Car::getInsurance) | |
.map(Insurance::getName); | |
} | |
} | |
class Person { | |
private Optional<Car> car; | |
public Person(Optional<Car> car) { | |
this.car = car; | |
} | |
public Optional<Car> getCar() { | |
return car; | |
} | |
} | |
class Car { | |
private Optional<Insurance> insurance; | |
public Car(Optional<Insurance> insurance) { | |
this.insurance = insurance; | |
} | |
public Optional<Insurance> getInsurance() { | |
return insurance; | |
} | |
} | |
class Insurance { | |
private String name; | |
public Insurance(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment