Optionally getting field

后端 未结 2 1722
执念已碎
执念已碎 2020-12-11 03:46

I have a class structure like this:

public class Foo {
    private FooB foob;

    public Optional getFoob() {
        return Optional.ofNullable         


        
2条回答
  •  长情又很酷
    2020-12-11 04:18

    Why you dont add a getValue methode to the class Foo? This would be a kind of delegation.

    public class Foo {
       ...
       public Integer getValue() {
           if (foob == null) {
              return null;
           }
           return foob.getValA();
       }
    }
    

提交回复
热议问题