缓存的可选<布尔>值 [英] Cached Optional<Boolean> values

查看:152
本文介绍了缓存的可选<布尔>值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎没有为类型可选中任何缓存的对象;布尔> 真正标准库可用值。我失去了他们的地方?

There doesn't seem to be any cached objects of type Optional<Boolean> for the true and false values available in the standard library. Am I missing them somewhere?

如果没有这样的对象,因为在我看来,这样会非常有用,为清晰和性能这让我感到吃惊。

It would surprise me if there were no such objects because it seems to me like this would be so useful, for both clarity and performance.

如果真的有没有这样的对象,这是为什么?

If there really are no such objects, why is that?

推荐答案

有任何理由来解决特定的优化策略到API。 可选实例是通过工厂方法获得的,它的行为对返回的对象的身份是故意不确定的。

There is no reason to fix a particular optimization strategy into the API. Optional instances are acquired via a factory method and it’s behavior regarding returned object identities is intentionally unspecified.

所以实施可以的有一个缓存设备内部,但它也可能是JVM的优化需要这样的事情照顾的情况。今天的JVM的Elid已经在热点地区例如创作可能的情况下,未来却JVM实现也可以注入缓存或重复数据删除设施的基于价值类

So implementations can have a caching facility internally but it may also be the case that the JVM’s optimizer takes care about such things. Today’s JVMs already elide instance creations in hotspots when possible, but future JVM implementations may also inject caching or de-duplication facilities for "value based classes".

另请参阅为什么我不可选在Java8使用基于身份的操作?

这篇关于缓存的可选&LT;布尔&GT;值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆