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

2

16
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
Verge answered 15/12, 2013 at 15:13 Comment(0)
A
35

You can use:

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

This happens because JComboBox is now a generic class.

Angulation answered 15/12, 2013 at 15:19 Comment(0)
S
7

As of Java 7, generics were introduced into JComboBox component. Maybe you were using Java6 before. You should add JComboBox<String> to the second line there.

Seminal answered 15/12, 2013 at 15:19 Comment(1)
Strange. It looks like one of the projects was using JRE7 and one is using JavaSE-1.7...Verge

© 2022 - 2024 — McMap. All rights reserved.