Ghasan غسان
Ghasan غسان

Reputation: 5857

Java Generic Classes Arrays

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?

Upvotes: 0

Views: 117

Answers (2)

Cristina_eGold
Cristina_eGold

Reputation: 1553

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.

Upvotes: 4

Dima
Dima

Reputation: 8652

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

Upvotes: 2

Related Questions