Given this code
final Double price = new Double(someString);
if(price != null <...>) {
Am I correct in assuming that price can NEVER be null here?
Given this code
final Double price = new Double(someString);
if(price != null <...>) {
Am I correct in assuming that price can NEVER be null here?
It can thrown NumberFormatException
but it can never be null
, because you are using the new
keyword.
Read the specifications: section 15.9.4 of the JLS:
The value of a class instance creation expression is a reference to the newly created object of the specified class. Every time the expression is evaluated, a fresh object is created.
A constructor therefore can never return null. However, an java.lang.OutOfMemoryError
may occur.
Yes, it can never be null. why do you doubt?