The following code compiles, but why am I getting a runtime exception?
String b = null; System.out.println(b.getClass());
Error:
java.lang.NullPointerException
How can I get the type of an object even if it is set to null?
Edit I understand that there is no object, but there is still an object b of type String. Even if it does not contain an object, it still has a type. How to get the type of an object, whether it contains an object or not.
source share