title: difference between int and Integer type in groovy
body: <p>I have just started learning groovy and I am reading "Groovy in Action".
  In this book I came across a statement that <strong>it doesn’t matter whether you declare or cast a variable to be of type int or Integer.Groovy uses the reference type ( Integer ) either way.</strong></p>
  
  <p>So I tried to assign <strong>null</strong> value to a variable with type <strong>int</strong></p>
  
  <pre><code>int a = null
  </code></pre>
  
  <p>But it is giving me below exception</p>
  
  <blockquote>
    <p>org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead
        at Script1.run(Script1.groovy:2)</p>
  </blockquote>
  
  <p>Then I tried to assign <strong>null</strong> value to a variable with type <strong>Integer</strong></p>
  
  <pre><code>Integer a = null
  </code></pre>
  
  <p>and it is working just fine.</p>
  
  <p>Can anyone help me understand how <code>groovy</code> behaves such way or the reason behind it?</p>