title: Populating generic array in java
body: <p>I am trying to populate an array of generic types but its always empty after the Array.fill i am using here. What can I be doing wrong?</p>
  
  <pre><code>  private &lt;T&gt; CartField&lt;T&gt;[] getPopulatedCart(T field) {
      CartField&lt;T&gt; cart = new CartField&lt;&gt;(field);
      CartField&lt;T&gt;[] cartFields = new CartField[0];
      Arrays.fill(cartFields, cart);
      return cartFields;
    }
  </code></pre>
  
  <p>This always returns an empty array, i can verify when debugging that the cart field makes it, even when inspecting the cart on the same line as Arrays.fill(cartFields, cart) it shows the value but on the return the array is empty.</p>
  
  <p>Any help or guidance would be appreciated.</p>