Skip to content

Instantly share code, notes, and snippets.

@pramoth
Created June 12, 2018 13:35
Show Gist options
  • Select an option

  • Save pramoth/3cd35ef8da84a3c0296adfde2cb9f9cc to your computer and use it in GitHub Desktop.

Select an option

Save pramoth/3cd35ef8da84a3c0296adfde2cb9f9cc to your computer and use it in GitHub Desktop.
package th.co.geniustree.demo;
import org.junit.Test;
public class OptionalTest {
@Test
public void no_optional() {
Home home = findHomeFromSomeWhere();
//print cc. of a car in my home
if (home != null) {
Car car = home.getCar();
if (car != null) {
Engine engine = car.getEngine();
if (engine != null) {
Piston piston = engine.getPiston();
System.out.println(piston.getCapacity());
}
}
}
}
private Home findHomeFromSomeWhere() {
return new Home();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment