title: Nullpointer exception with conditional operator, (ternary operator) but not with if else
body: <p>I'm getting nullpointer exception if I use ternary operator.</p>
  
  <pre><code>Integer val = null;
  Object res = val == null ? val : val.intValue();
  </code></pre>
  
  <p>But not with if else</p>
  
  <pre><code>    Integer val = null;
      Object res;
    if( val == null ) {
        res  = val;
    } else {
        res = val.intValue();
    }
  </code></pre>
  
  <p>Can anyone please explain why?</p>
  
  <p>Thanks
  Sudar</p>