Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic Array Creation

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
Amgad Muhammad
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this

HashMap<String, String>[] m = new HashMap<String, String>[3];
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still raises the same error !!
 
Amgad Muhammad
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the only way to do it is to use the wildcard

HashMap<?, ?>[] x=new HashMap<?, ?>[3]
 
Prakash Subramanian
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for a great help , Amgad and Prakash !
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15282
39
Android IntelliJ IDE Java Scala Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic