crwdns119905:0crwdne119905:0

crwdns119907:0crwdne119907:0

crwdns119909:0crwdne119909:0

crwdns119911:0crwdne119911:0

crwdns119913:0crwdne119913:0

crwdns119915:0crwdne119915:0

../../_images/optionals1.png

crwdns119917:0crwdne119917:0

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

crwdns119919:0crwdne119919:0

  • crwdns119921:0crwdne119921:0

  • crwdns119923:0crwdne119923:0

../../_images/optionals2.png

crwdns119925:0crwdne119925:0

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

crwdns119927:0crwdne119927:0

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

crwdns119929:0crwdne119929:0

crwdns119931:0crwdne119931:0

crwdns119933:0crwdne119933:0

crwdns119935:0crwdne119935:0

  • crwdns119937:0crwdne119937:0

  • crwdns119939:0crwdne119939:0

  • crwdns119941:0crwdne119941:0

  • crwdns119943:0crwdne119943:0

  • crwdns119945:0crwdne119945:0

crwdns119947:0crwdne119947:0

crwdns119949:0crwdne119949:0

crwdns119951:0crwdne119951:0

crwdns119953:0crwdne119953:0

crwdns119955:0crwdne119955:0

../../_images/optionals3.png

crwdns119957:0crwdne119957:0

crwdns119959:0crwdne119959:0

crwdns119961:0crwdne119961:0

crwdns119963:0crwdne119963:0

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

crwdns119965:0crwdne119965:0

crwdns119967:0crwdne119967:0

crwdns119969:0crwdne119969:0

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

crwdns119971:0crwdne119971:0

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

crwdns119973:0crwdne119973:0

crwdns119975:0crwdne119975: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();
}

crwdns119977:0crwdne119977:0

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

crwdns119979:0:doc:crwdne119979:0

Note

crwdns119981:0crwdne119981:0