1

I created a bunch of collection like this :

Collection<JTextField> myJTextfield = new ArrayList<JTextField>();
Collection<JComboBox> myJComboBox = new ArrayList<JComboBox>();
Collection<JLabel> myJLabel = new ArrayList<JLabel>();

and I'm getting a warning only in the JComboBox collection which it says:

ComboBox is a raw type. References to generic type JComboBox should be parameterized

I looked for what it means in google, they talk about generic types but I still don't get it really. my questions are :

  • what does it means?

  • why the warning appears only for the JComboBox collection??

  • how can I remove it?

    I'll appreciate any explanation.

Community
  • 1
  • 1
cbInfo009
  • 71
  • 1
  • 4
  • 14
  • `JComboBox` can accept generics – MadProgrammer Dec 17 '15 at 01:42
  • @MadProgrammer can you explain more? I dont understand the generic type ... i'm creating a collection of type JComboBox .. where is the generic type here ? what is a raw type?? and what about parameter ?? – cbInfo009 Dec 17 '15 at 01:48
  • I'm guessing, as I don't get the warning, but because `JComboBox` can accept generics, you `myJComboBox` can contain any type `JComboBox`. The compiler can not guarantee the type of `JComboBox` which might be added or retrieved from the collection – MadProgrammer Dec 17 '15 at 01:52
  • @MadProgrammer well I added this Collection> myJComboBox = new ArrayList>(); I specified thye type think I got what do you mean :) – cbInfo009 Dec 17 '15 at 01:54
  • @MadProgrammer so I can't add another type of JComboBox which is an integer to the same collection?? – cbInfo009 Dec 17 '15 at 01:58
  • @MadProgrammer i men if I've a multiple protected JComboBox typeAlgo; and protected JComboBox typeAlgo; and i want to do a same action on them like make them not visible , i've to create 2 collection ?? one for type JComboBox and another for type JComboBox??? – cbInfo009 Dec 17 '15 at 02:00
  • It depends, if you don't care about the data type, you might be able to use JComboBox> – MadProgrammer Dec 17 '15 at 02:06
  • @MadProgrammer ok good :) – cbInfo009 Dec 17 '15 at 02:09

1 Answers1

1

JComboBox is a generic class. You should modify it to be something like:

Collection<JComboBox<String>> myJComboBox = new ArrayList<JComboBox<String>>();
CMPS
  • 7,733
  • 4
  • 28
  • 53