When we are using System.out.println(null)
then we get compilation error and to resolve this we typecast null
like:
System.out.println((String)null)
and then it starts working fine.
My questions is how we are allowed to typecast null
when we say that null
is something which is not pointing to any location and thus has no value in itself.
Also if null is not pointing to any location then the object which is null will get Garbage collected then why we are using it at first place? I know it is litle bit out of the topic but it came to my mind.
I have seen few answers in below link but they mostly talk about println method functionality and implementation but I want to know about null only.