Bookmark Topic Watch Topic
  • New Topic

Generic JComboBox arrays

 
Chris Kimball
Ranch Hand
Posts: 35
Java
  • Mark post as helpful
  • send pies
  • Report post to moderator


I declare an array of JComboBox's , all parameterized by Strings.

JComboBox<String>[] Choices ;

At the time, I don't know how long the array must be.

Alas, when I do know it and want N JComboBox's parameterized by String

Choices = new JComboBox<String>[N];

I get an error, "Cannot create a generic array of JComboBox<String>". But Choices isn't a generic is it?

Thanks,

Chris
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Why not use a List<JComboBox<String>>? You get rid of both the size not being known (since most Lists can grow), and you get rid of the compiler error.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please always use one thread for one question. Please continue all discussion here.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!