title: Get type of an object with an object of null?
body: <p>The following code does compile, but why do I get a run time exception?</p>
  
  <pre><code>String b = null;
  System.out.println(b.getClass());
  </code></pre>
  
  <p>Error I get is</p>
  
  <pre><code>java.lang.NullPointerException
  </code></pre>
  
  <p>How can I get the type of the object even if it's set to null?</p>
  
  <p><strong>Edit</strong>
  I realize there is no object present, but there still is an object b of type String. Even if it holds no object, it still has a type. How do I get at the type of an object, regardless of if it holds an object or if it does not.</p>