crwdns139519:0crwdne139519:0

crwdns139521:0crwdne139521:0

crwdns139523:0crwdne139523:0

crwdns139525:0crwdne139525:0

crwdns139527:0crwdne139527:0

crwdns139529:0crwdne139529:0

../../_images/optionals1.png

crwdns139531:0crwdne139531:0

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

crwdns139533:0crwdne139533:0

  • crwdns139535:0crwdne139535:0

  • crwdns139537:0crwdne139537:0

../../_images/optionals2.png

crwdns139539:0crwdne139539:0

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

crwdns139541:0crwdne139541:0

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

crwdns139543:0crwdne139543:0

crwdns139545:0crwdne139545:0

crwdns139547:0crwdne139547:0

crwdns139549:0crwdne139549:0

  • crwdns139551:0crwdne139551:0

  • crwdns139553:0crwdne139553:0

  • crwdns139555:0crwdne139555:0

  • crwdns139557:0crwdne139557:0

  • crwdns139559:0crwdne139559:0

crwdns139561:0crwdne139561:0

crwdns139563:0crwdne139563:0

crwdns139565:0crwdne139565:0

crwdns139567:0crwdne139567:0

crwdns139569:0crwdne139569:0

../../_images/optionals3.png

crwdns139571:0crwdne139571:0

crwdns139573:0crwdne139573:0

crwdns139575:0crwdne139575:0

crwdns139577:0crwdne139577:0

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

crwdns139579:0crwdne139579:0

crwdns139581:0crwdne139581:0

crwdns139583:0crwdne139583:0

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

crwdns139585:0crwdne139585:0

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

crwdns139587:0crwdne139587:0

crwdns139589:0crwdne139589: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();
}

crwdns139591:0crwdne139591:0

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

crwdns139593:0:doc:crwdne139593:0

Note

crwdns139595:0crwdne139595:0