JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized

tssguy123 picture tssguy123 · Dec 15, 2013 · Viewed 23k times · Source
String[] boxOptions = {"1","2","4","8","16","20","40","100","400"};
JComboBox box = new JComboBox(boxOptions);

I had these exact lines of code in my program before, and wasn't getting this error. I did a bit of searching and the results I found are going a bit over my head. Any ideas?

The error is:

JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized

Answer

BobTheBuilder picture BobTheBuilder · Dec 15, 2013

You can use:

JComboBox<String> box = new JComboBox<>(boxOptions);

This happens because JComboBox is now a generic class.