Since Java 7 JComboBox
is a generic type, which means that when declaring a variable of this type you are expected to perform a generic type invocation by supplying a type argument which represents "the type of the elements of this combo box" [from the API].
In your case this means:
JComboBox<String> someComboBox = new JComboBox<>(season);
Interestingly the Java Tutorial on JComboBox appears not to have been updated to the generic version of JComboBox
.
If, for this or any other reason, you wish to use JComboBox
without doing a generic type invocation, this is still possible because Java supports using raw types.
A raw type is the name of a generic class or interface without any type arguments.
So you can use the JComboBox
raw type as:
JComboBox someComboBox = new JComboBox(season);
Although this is not recommended, if you just want to experiment or follow the tutorial, then it should not be a big deal.
If you find the compiler warnings are distracting, you might be able to get rid of them by appropriately setting the compiler error/warning properties in your IDE. Alternatively, you can get rid of them using the @SuppressWarnings annotation. If supported by your compiler, adding the annotation instance to your code should get rid of the warning:
@SuppressWarnings({"rawtypes","unchecked"})
JComboBox box = new JComboBox(season);
See also this post for more info on @SuppressWarnings
.