Set for single instances of classes
<p>I have a <code>Set</code> of objects and I don't want to allow to store there more than one instance of any class. Which solution is the best:</p>

<ul>
<li>check if there is an instance of given class in a set (doesn't seem to be efficient)</li>
<li>implement <code>hashCode</code> to return constant and <code>equals</code> to return <code>o != null &amp;&amp; o.getClass() == getClass()</code></li>
<li>make own implementation of <code>Set</code> (almost like first option)</li>
<li>anything else? maybe there is already such a set?</li>
</ul>
