title: how to catch method type (generick type) at runtime
body: <p>I have to do some catching of type at runtime. I couldn't figure out how to do this.</p>
  
  <p>Tricky place is that this type is generic.</p>
  
  <p><strong><em>Code</em></strong> snippet:</p>
  
  <pre><code>public class Ship&lt;T&gt; {
  
      private ArrayList&lt;T&gt; passangers = new ArrayList&lt;T&gt;();
  
      public Ship(ArrayList&lt;T&gt; passangers) {
          this.passangers = passangers;
      }
  
      public void addPassanger(T object) {
          passangers.add(object);
      }
      // ... rest of class
  }
  </code></pre>
  
  <p>How to catch which type is into method <code>addPassanger(T object)</code> at runtime.
  Catch this type of <code>T</code>.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I follow <a href="https://stackoverflow.com/users/335858/dasblinkenlight">dasblinkenlight</a> suggestions.</p>
  
  <p>And added into main():</p>
  
  <pre><code>    Ship&lt;Droid&gt; victoria = new Ship&lt;Droid&gt;(new ArrayList&lt;Droid&gt;(), Droid.class);
  
      victoria.addPassanger(new Droid("Christofor Columb"));
      victoria.addPassanger(new Droid("Fernando Magelan"));
      victoria.addPassanger(new Droid("James Kuk"));
  
      System.out.print("Passengers type is:");
      victoria.getPassengerType();
      System.out.println();
      victoria.showPassangers();
  </code></pre>
  
  <p>But output is next:</p>
  
  <pre><code>Passengers type is:
  At the sheep are presented:
  1 Christofor Columb
  2 Fernando Magelan
  3 James Kuk
  </code></pre>
  
  <p>Here line:</p>
  
  <blockquote>
    <p>victoria.getPassengerType();</p>
  </blockquote>
  
  <p>which should return class type return nothing.</p>
  
  <p><strong>Any suggestions?</strong></p>