سؤال

For some reason I have to maintain a Java 1.3 project. 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:

Boolean disableAllThings = Boolean.FALSE;

نصائح أخرى

I think you're looking for Boolean.FALSE (and Boolean.TRUE). They were around since the beginning of Java, and they certainly were there in Java 1.3.1.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top