Return "null" on primitive return type function?
<p>I have a function which returns an <code>int</code> value for a given key (from a <code>HashMap&lt;String, Integer&gt;</code>). If the key doesn't exist, I want to return something the caller can check for. It seems that, most commonly, this would be a "<em>returns -1 if key doesn't exist</em>" kind of thing. However, I can't reserve -1 for that purpose in my case, because negative numbers are feasible values for keys which <em>do</em> exist.</p>

<p>The only other options I have been able to come up with are the following:</p>

<ol>
<li>Change return type to <code>Integer</code> wrapper class and check for <code>null</code></li>
<li>Return something very unlikely, such as <code>Integer.MIN_VALUE</code></li>
<li>Make an additional <code>boolean keyExists(String key)</code> function which should always be called first</li>
<li>Switch to <code>float</code> and use <code>NaN</code> instead</li>
</ol>

<p>I am writing this in Java, but people from similar language backgrounds are welcome to post. Thanks!</p>
