简体   繁体   English

Java 1.3中的布尔拳击

[英]Boolean boxing in Java 1.3

For some reason I have to maintain a Java 1.3 project. 由于某种原因,我必须维护一个Java 1.3项目。 I use some Boolean but it seems that to give them default values I have to box them like this 我使用一些布尔值,但似乎要给它们提供默认值,我必须像这样将它们装箱

Boolean disableAllTheThings = new Boolean(false);

Is there a way to have this automatically with a constant somewhere such as 有没有办法自动在某个地方使用常量

Boolean disableAllTheThings = FALSE_CONSTANT;

It is not that important it just feels weird to box Booleans. 装箱布尔值感觉很奇怪,这并不重要。

There is no boxing in your example, but you create an unnecessary object. 您的示例中没有装箱,但是您创建了一个不必要的对象。 How about using the constant provided by the Boolean class (link to 1.3 API) instead: 如何使用布尔类(链接到1.3 API)提供常量呢

Boolean disableAllThings = Boolean.FALSE;

I think you're looking for Boolean.FALSE (and Boolean.TRUE ) . 我认为您正在寻找Boolean.FALSE (和Boolean.TRUE They were around since the beginning of Java, and they certainly were there in Java 1.3.1. 自Java诞生以来,它们就存在了,并且在Java 1.3.1中肯定存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM