Why does private Boolean shouldDropTables; assign true by default to the variable instead of NULL, like when writing private Integer anInteger;?
I am asking because I came across some code where there was an evaluation on a shouldDropTables Boolean variable being NULL or not determining whether to execute a method.
Boolean (with a uppercase 'B') is a Boolean object, which if not assigned a value, will default to null. boolean (with a lowercase 'b') is a boolean primitive, which if not assigned a value, will default to false.
Boolean objectBoolean;
boolean primitiveBoolean;
System.out.println(objectBoolean); // will print 'null'
System.out.println(primitiveBoolean); // will print 'false'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With