Skip to main content

Why specific type of array instantion is not allowed?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
vikassarin
Offline
Joined: 2014-07-30

Why specific type of array instantion is not allowed?

The array instantiaion
Gen arrGen[ ] = new Gen[10]
is not allowed

but the wildcard instantiation
Gen<?> arraGen = new Gen<?>[10]
is allowed

for type checking.

As per System Programming, the specific instantiation is compile time and allocates the memory for each elements of the array(type of elements are same) at compile time. On the other hand, the wildcard instantiation is dynamic and at runtime and allow to store different type of elements in the array violating the definition of array that the array contains same type of elements.

Please clarify me!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vikassarin
Offline
Joined: 2014-07-30

clarified............it is an array of objects and can store any values in the properties of the objecs. The array definition would not be violated!