crwdns130657:0crwdne130657:0

crwdns130659:0crwdne130659:0

crwdns130661:0crwdne130661:0

crwdns130663:0crwdne130663:0

crwdns130665:0crwdne130665:0

crwdns130667:0crwdne130667:0

../../_images/optionals1.png

crwdns130669:0crwdne130669:0

public void someEventHandler(Entity someEntity) {
    Foo entityFoo = someEntity.getFoo();
    entityFoo.bar();
}

crwdns130671:0crwdne130671:0

  • crwdns130673:0crwdne130673:0

  • crwdns130675:0crwdne130675:0

../../_images/optionals2.png

crwdns130677:0crwdne130677:0

public void someEventHandler(Entity someEntity) {
    Foo entityFoo = someEntity.getFoo();
    entityFoo.bar();
}

crwdns130679:0crwdne130679:0

public void someEventHandler(Entity someEntity) {
    Foo entityFoo = someEntity.getFoo();
    if (entityFoo == null) {
        entityFoo = MyPlugin.DEFAULT_FOO;
    }
    entityFoo.bar();
}

crwdns130681:0crwdne130681:0

crwdns130683:0crwdne130683:0

crwdns130685:0crwdne130685:0

crwdns130687:0crwdne130687:0

  • crwdns130689:0crwdne130689:0

  • crwdns130691:0crwdne130691:0

  • crwdns130693:0crwdne130693:0

  • crwdns130695:0crwdne130695:0

  • crwdns130697:0crwdne130697:0

crwdns130699:0crwdne130699:0

crwdns130701:0crwdne130701:0

crwdns130703:0crwdne130703:0

crwdns130705:0crwdne130705:0

crwdns130707:0crwdne130707:0

../../_images/optionals3.png

crwdns130709:0crwdne130709:0

crwdns130711:0crwdne130711:0

crwdns130713:0crwdne130713:0

crwdns130715:0crwdne130715:0

public void someEventHandler(Entity someEntity) {
    Optional<Foo> entityFoo = someEntity.getFoo();
    if (entityFoo.isPresent()) {
        entityFoo.get().bar();
    }
}

crwdns130717:0crwdne130717:0

crwdns130719:0crwdne130719:0

crwdns130721:0crwdne130721:0

public void someEventHandler(Entity someEntity) {
    Foo entityFoo = someEntity.getFoo().orElse(MyPlugin.DEFAULT_FOO);
    entityFoo.bar();
}

crwdns130723:0crwdne130723:0

public void someEventHandler(Entity someEntity) {
    someEntity.getFoo().orElse(MyPlugin.DEFAULT_FOO).bar();
}

crwdns130725:0crwdne130725:0

crwdns130727:0crwdne130727:0

public void someEventHandler(Entity someEntity, Entity entity2) {
    Foo entityFoo = someEntity.getFoo();
    if (entityFoo == null) {
        entityFoo = entity2.getFoo();
    }
    if (entityFoo == null) {
        entityFoo = MyPlugin.DEFAULT_FOO;
    }
    entityFoo.bar();
}

crwdns130729:0crwdne130729:0

public void someEventHandler(Entity someEntity, Entity entity2) {
    someEntity.getFoo().orElse(entity2.getFoo().orElse(MyPlugin.DEFAULT_FOO)).bar();
}

crwdns130731:0:doc:crwdne130731:0

Note

crwdns130733:0crwdne130733:0