• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generics question  RSS feed

 
Henry Eck
Greenhorn
Posts: 7
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about declaring arrays of a generic class.

The following statement (full context is below) will not compile, and causes the "generic array creation" error. My question is why (?). The generic type is specified, so I don't see why the compiler should have a problem with this.

but

compiles okay.

Any insights would be appreciated. Cheers.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because of how generics are implemented; if you search the web for the error message you'll find a lot of discussions and workarounds, most of which are easily summed up as "use a collection, not an array" or "use Array.newInstance and cast"

http://forums.sun.com/thread.jspa?forumID=316&threadID=457033

See Gafter's response.

Bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5098163
 
Henry Eck
Greenhorn
Posts: 7
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. that helps.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!