title: How to get constructor by inexact type of parameters?
body: <p>I need to find a constructor, which can accept both class and it's superclass.</p>
  
  <p>The <code>get</code> method does not work, causing <code>NoSuchMethodException</code>:</p>
  
  <pre><code>package tests.java;
  
  import java.lang.reflect.Constructor;
  
  public class Try_ConstructorReflection {
  
      public static class A {
  
      }
  
      public static class A1 extends A {
  
      }
  
      public static class A2 extends A {
  
      }
  
      public static class B {
          public B(A a) {
          }
      }
  
      public static class B1 {
          public B1(A1 a) {
          }
      }
  
      public static class B2 {
          public B2(A2 a) {
          }
      }
  
      public static void main(String[] args) throws NoSuchMethodException, SecurityException {
  
          Class&lt;?&gt; cls = B.class;
  
          Constructor&lt;?&gt; cons = cls.getConstructor(B1.class);
  
          System.out.println(cons.toString());
  
      }
  
  }
  </code></pre>
  
  <p>Is the only way to accomplish the task is to enumerate all constructor manually with <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getConstructors--" rel="nofollow"><code>getConstructors()</code></a>?</p>