title: Java function returning int instead of Integer
body: <p>Folks, I'm writing a resource manager which can manager different types of resources. Resources can be integers or some custom types. So, I defined an interface like this:</p>
  
  <pre><code>public interface ResourceManagerInterface&lt;R&gt; {
      /**
       * allocateResource:
       * Allocate a resource from the resource pool
       * @return
       */
      R allocateResource() throws ResourceUnavailableException;
  
      /**
       * freeResource:
       * Deallocate/Return/Free a resource and make it available in the pool.
       * @param resource
       */
      void freeResource(R resource) throws InvalidResourceException;
  }
  </code></pre>
  
  <p>One of the implementors of this interface manages resource of type "int". Since I could not do:</p>
  
  <pre><code>public class NumericResourceManager implements ResourceManagerInterface&lt;int&gt;
  </code></pre>
  
  <p>I ended up doing:</p>
  
  <pre><code>public class NumericResourceManager implements ResourceManagerInterface&lt;Integer&gt; 
  </code></pre>
  
  <p>Note: used "Integer" instead of "int".</p>
  
  <p>I had a piece of code like this:</p>
  
  <pre><code>@Override
      public Integer allocateResource() throws ResourceUnavailableException {
          try {
              return internalToExternal(firstAvailableResource());
          } catch (ResourceUnavailableException e) {
              throw e;
          }
      }
  </code></pre>
  
  <p>The function internalToExternal() returns an "int" and NOT an "Integer".</p>
  
  <p>Questions:
  1. Is there an automatic conversion from "int" to "Integer"?</p>
  
  <ol start="2">
  <li><p>I use the interface like below:</p>
  
  <p>int someint = someManager.allocateResource();</p></li>
  </ol>
  
  <p>That is, I'm getting the return value in an "int" and not "Integer". This is also working fine.</p>
  
  <p>Since it works, I'm a bit confused if this is safe and I can leave this as is?</p>
  
  <p>Thanks for your time.</p>