How specific should my method header be about it's return type?
<p>If I have a method that is to return a TreeSet of integers how should I declare it?</p>

<p><strong>Option A</strong></p>

<pre><code>public Collection returnSortedIntegers()
</code></pre>

<p><strong>Option B</strong></p>

<pre><code>public Set returnSortedIntegers()
</code></pre>

<p><strong>Option C</strong></p>

<pre><code>public Set&lt;Integer&gt; returnSortedIntegers()
</code></pre>

<p><strong>Option D</strong></p>

<pre><code>public TreeSet&lt;Integer&gt; returnSortedIntegers()
</code></pre>

<hr>

<p>The reason I ask is because I was getting the <code>-Xlint:unchecked</code> message when I compiled a class that used this method in one of it's methods. I had no problems compiling it when it looked like Option A, it was only when I compiled the different class that used the method that I got the xlint message which is why I have changed it to Option C and the message has gone away.</p>

<hr>

<p>Thank you for your answers, it would appear that this is winning</p>

<p><strong>Option E</strong></p>

<pre><code>public SortedSet&lt;Integer&gt; returnSortedIntegers()
</code></pre>

<p>I am studying Java at the moment so it's quite new to me and I wasn't aware of the SortedSet interface, I was only aware that TreeSet was a subclass of Set. As always Stack Overflow has enlightened me.</p>
