0

For boolean fields in Java Model class is it better to use Boolean object or primitive boolean

What are the best use cases for each of them

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kashif Imran
  • 579
  • 3
  • 9
  • 29
  • http://stackoverflow.com/questions/3728616/boolean-vs-boolean-in-java – brso05 Jun 04 '15 at 13:38
  • 1
    If the field should be able to hold `null`, use `Boolean`, if not, use `boolean`. – aioobe Jun 04 '15 at 13:38
  • If the field should be able to hold `null`, it's not really a boolean at all. Consider an `enum`, or perhaps the [`Optional`](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html) class (available in [Guava](https://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained) before Java 8). – dimo414 Jun 04 '15 at 17:04

0 Answers0