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);
    }
}

 

 

posted @ 2023-12-15 11:11  papering  阅读(2)  评论(0编辑  收藏  举报