DEV Community


Discussion on: Effective Java Tuesday! Avoid Creating Unnecessary Objects!

ujaehrig profile image

The Boolean example is IMO not the best example for a factory method. As Boolean provides the two boolean values as immutable constants which are easier to use.

Also the parseBoolean (not parseValue) method returns a native boolean, which needs to be boxed. This is usually done via the Boolean#valueOf method, which will also return the constants.

You can see this quite nicely in the jshell:

Boolean.parseBoolean("true") == Boolean.TRUE