title: What are my alternatives to "instanceof" when the reference is null in Java?
body: <p>I have a method that receives a parameter which can be null. I have used <code>instanceof</code> to check the type but if the parameter comes null, <code>instanceof</code> returns null. I have read the documentation and it is how <code>instanceof</code> works. In this case , I want to check the type of the passed parameter  even if the value is null.
  example</p>
  <pre class="lang-java prettyprint-override"><code>public static void checkType(Object yourObject) {
      if(yourObject instanceof String) {  // this fails if null passed, even if declared as String
      print(&quot;You have passed a String&quot;);    
      }
  }
  </code></pre>
  <p>What could I do in these cases?</p>
  <p>My goal is, that:</p>
  <pre class="lang-java prettyprint-override"><code>String myvar = null; 
  checkType(myvar); 
  </code></pre>
  <p>would print:</p>
  <blockquote>
  <p>&quot;You have passed a String&quot;</p>
  </blockquote>