0

I was reading this answer, and now got confused about the normal array declaration and this piece of code used to create arrays for generic classes:

Gen<?> gens[] = new Gen<?>[10];

What does this do exactly, and how it is different from the normal array declaration?

Community
  • 1
  • 1
Ghasan غسان
  • 4,866
  • 4
  • 27
  • 39

2 Answers2

4

I'm only a beginner so I might be wrong, but this is my take on the declaration you've written:

Gen is a generic class, like a template. The question mark signifies a wildcard. Therefore, you have initialized an array of 10 Gen templates that may be configured with any type of object.

user207421
  • 289,834
  • 37
  • 266
  • 440
Cristina_eGold
  • 1,251
  • 19
  • 35
2

it is an array with 10 places that holds a generic class of type Gen that is a generic class of any object

Dima
  • 8,448
  • 4
  • 25
  • 56