How to map an OptionalLong to an Optional?

前端 未结 4 1988
逝去的感伤
逝去的感伤 2021-02-20 01:59

I have an instance of OptionalLong. But one of my libraries requires an Optional as a parameter.

How can I convert my Option

4条回答
  •  礼貌的吻别
    2021-02-20 02:26

    This should work.

    Optional returnValue = Optional.empty();
    if(secondScreenHeight.isPresent()) {
          returnValue = Optional.of(secondScreenHeight.getAsLong());
    }
    

提交回复
热议问题