title: Java: Trouble with Generics & Collection type detection
body: <p>I have a class called DataSet with various constructors, each specifying a different type of variable.  It might look a bit like this:</p>
  
  <pre><code>public class DataSet
  {
      private HashSet Data;
  
  
      public DataSet( DataObject obj )
      {
          Data = new &lt;DataObject&gt;HashSet();
          Data.add( obj );
      }
  
      public DataSet( ObjectRelationship rel )
      {
          Data = new &lt;ObjectRelationship&gt;HashSet();
          Data.add( rel );
      }
      // etc.
  </code></pre>
  
  <p>Note: I haven't yet gotten to test that code due to incomplete parts (which I'm building right now).</p>
  
  <p>In a function that I'm currently building, <code>getDataObjects()</code>, I need to return all DataObject objects that this set represents.  In the case of constructors that initiate the class's HashSet, <code>Data</code> with types other than <code>DataObject</code> (such as the above <code>ObjectRelationship</code>), there obviously won't be any DataObjects stored within.  In this case, I need to be able to detect the type that the HashSet 'Data' was initiated with (like, to tell if it's 'ObjectRelationship' or not, I mean).  How do I do this?
  <br />
  <br />
  <br />
  <br />
  <strong>tl;dr</strong>: How do I tell the type that a Collection (in this case, a HashSet) was initiated with in my code (like with an 'if' or 'switch' statement or something)?</p>