title: Java sub form with generic type
body: <p>I have the <strong>Form</strong> classes like this</p>
  <pre class="lang-java prettyprint-override"><code>@Data
  public class Form&lt;T&gt; {
      private T dynamicSubForm;
      private String firstName;
      private Short age;
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>@Data
  public class SubForm1 {
      private String nickname;
      ...
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>@Data
  public class SubForm2 {
      private Short height;
      ...
  }
  
  </code></pre>
  <p>and I have RestController like this</p>
  <pre class="lang-java prettyprint-override"><code>@RestController
  public class MyRestController {
  
      @GetMapping(“/form1”)
      public ResponseEntity&lt;String&gt; getForm1(Form&lt;SubForm1&gt; form) {
          form.getDynamicSubForm().getNickname(); // Error occurs here that type of form.dynamicSubForm is &quot;Object&quot; instead of &quot;SubForm1&quot;.
          return new ResponseEntity&lt;&gt;(&quot;Hello World!&quot;, HttpStatus.OK);
      }
  
      @GetMapping(“/form2”)
      public ResponseEntity&lt;String&gt; getForm2(Form&lt;SubForm2&gt; form) {
          form.getDynamicSubForm().getHeight(); // Error occurs here that type of form.dynamicSubForm is &quot;Object&quot; instead of &quot;SubForm2&quot;.
          return new ResponseEntity&lt;&gt;(&quot;Hello World!&quot;, HttpStatus.OK);
      }
  
  }
  </code></pre>
  <p>My question is how to instantiate the dynamicSubForm with the target generic type.</p>