null Casting null objects to Other Types in Java
null
What is null in Java - Java Code Geeks https://examples.javacodegeeks.com/what-is-null-in-java/
public
class
CastingNull {
public
static
void
main(String[] args) {
String myStr = (String)
null
;
// null can be type cast to String
Integer myItr = (Integer)
null
;
// it can also be type casted to Integer
Double myDbl = (Double)
null
;
// yes it's possible, no error
System.out.println(
"Printing null casted to String"
);
System.out.println(myStr);
System.out.println(
"Printing null casted to Integer"
);
System.out.println(myItr);
System.out.println(
"Printing null casted to Double"
);
System.out.println(myDbl);
}
}