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 غسان
  • 5,577
  • 4
  • 33
  • 44
  • 3
    Take a look at this great Q&A simple and short tutorial: http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html – acdcjunior May 19 '13 at 09:42

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
  • 305,947
  • 44
  • 307
  • 483
Cristina_eGold
  • 1,463
  • 2
  • 22
  • 41
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,586
  • 4
  • 28
  • 57