Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

found raw type: JComboBox

Tags:

java

jcombobox

I have very simple source file GuiApp1.java which I am trying to compile with cmd javac. It gives me warning that :

C:\Users\Thakkar\Java>javac GuiApp1.java
Note: GuiApp1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

so I used cmd as javac -Xlint GuiApp1.java for compile the source file.

it gave me 6 warnings e.g.

GuiApp1.java:48: warning: [rawtypes] found raw type: JComboBox
        JComboBox fruits = new JComboBox(fruitOptions);
        ^
  missing type arguments for generic class JComboBox<E>
  where E is a type-variable:
    E extends Object declared in class JComboBox

how can i solve this?

like image 589
Bharati Thakkar Avatar asked Nov 28 '25 17:11

Bharati Thakkar


1 Answers

Starting from Java 7 many Swing components use generics, so older code will produce a warning for raw types.

For the combobox example you can eliminate the warning if you provide the type of the objects it holds e.g. you should use JComboBox<String> fruits = new JComboBox<>(fruitOptions); if fruitOptions is a String[]. If you use some other type change it accordingly.

like image 150
c.s. Avatar answered Dec 01 '25 05:12

c.s.