JComboBox Security Difference in Java 7 and Java 6

I am using a project that can be compiled on both Java 6 and Java 7 platforms. One of the GUI classes uses JComboBox. Because JComboBox changed its specification in Java 7 to a generic type, it requires a parametric declaration of the component.

In a Java 6 declaration, for example:

JComboBox mybox; 

OK and gives no errors, no warnings.

In Java 7, the same component declaration gives a warning

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

Providing parameters on request of Java 7:

 JComboBox<String> mybox; 

resolves warnings for the Java 7 platform, but I get a compilation error in Java 6.

What can I do in this case, so both Java 6 and 7 platforms can live in peace for my project?

+4
source share
1 answer

You can use @SuppressWarnings("rawtypes") to ignore the generics warning. Note that getSelectedItem does not use generics. Once you have fully migrated to Java 7, remove / fix the warnings.

+2
source

Source: https://habr.com/ru/post/1438924/


All Articles