aspose file tools*
The moose likes Java in General and the fly likes Generic Array Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generic Array Creation" Watch "Generic Array Creation" New topic
Author

Generic Array Creation

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Hi All,

I am practicing some generics in java , i can complie this code


But not this :


It raise an error s\, saying : "Generic Array Creation"

Whats the problem ??

Thanks in advance !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Amgad Muhammad
Ranch Hand

Joined: Mar 26, 2008
Posts: 46
try this

HashMap<String, String>[] m = new HashMap<String, String>[3];


SCJP5-(100%)
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

still raises the same error !!
Amgad Muhammad
Ranch Hand

Joined: Mar 26, 2008
Posts: 46
check this
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Hi

I am new to this kind of bugs !(encountering my first Java bugs ever !!)
I explore the link , but not found the exact solution over it . Please Help and suggest how to overcome this bug !!
Amgad Muhammad
Ranch Hand

Joined: Mar 26, 2008
Posts: 46
the only way to do it is to use the wildcard

HashMap<?, ?>[] x=new HashMap<?, ?>[3]
Prakash Subramanian
Ranch Hand

Joined: Feb 03, 2005
Posts: 32
Pretty interesting. The reason behind this particular design was to maintain compatibility with existing code. This is directly related to generics. Generic types for which arrays cannot be created are said to be non-reifiable. The meaning of reify according to the dictionary is to treat something abstract as if it was concrete. The meaning makes it a bit easier to understand
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Thanks for a great help , Amgad and Prakash !
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14149
    
  18

Here is some more background info: Java generics quirks


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generic Array Creation