如何将OptionalLong映射到Optional< Long>? [英] How to map an OptionalLong to an Optional<Long>?
本文介绍了如何将OptionalLong映射到Optional< Long>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 OptionalLong
的实例。但是我的一个库需要可选< Long>
作为参数。
I have an instance of OptionalLong
. But one of my libraries requires an Optional<Long>
as a parameter.
如何转换我的 OptionalLong
进入可选< Long>
?
我在做梦关于这样的事情:
I was dreaming about something like this:
OptionalLong secondScreenHeight = OptionalLong.of(32l); // or: OptionalLong.empty()
api.setHeight(secondScreenHeight.maptoRegularOptional()); // .maptoUsualOptional does not exist
推荐答案
我不知道了解更简单的解决方案,但这将满足您的需求。
I don't know simpler solutions but this will do what you need.
OptionalLong secondScreenHeight = OptionalLong.of(32l);
Optional<Long> optional = secondScreenHeight.isPresent()
? Optional.of(secondSceenHeight.getAsLong())
: Optional.empty();
api.setHeight(optional);
这篇关于如何将OptionalLong映射到Optional< Long>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文