The JComboBox type is not generic; it cannot be parameterized with the <Object> arguments

I have code for my Java project, and one of the classes is shown below, but when I want to run this code, I will get a compilation error in this class, one piece of code:

package othello.view; import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import othello.ai.ReversiAI; import othello.controller.AIControllerSinglePlay; import othello.controller.AIList; import othello.model.Board; import othello.model.Listener; @SuppressWarnings("serial") public class TestFrameAIVSAI extends JFrame implements ActionListener, Logger, Listener { private static Border THIN_BORDER = new EmptyBorder(4, 4, 4, 4); public JComboBox<Object> leftAICombo; public JComboBox<Object> rightAICombo; private JButton startTest; private JButton pauseTest; 

The error comes from two lines public JComboBox<Object> leftAICombo; and public JComboBox<Object> rightAICombo; , and error:

The type JComboBox is not generic; it cannot be parameterized with arguments <Object>

What is the problem?

+4
source share
2 answers

Change the bottom lines

  public JComboBox<Object> leftAICombo; public JComboBox<Object> rightAICombo; 

to

 public JComboBox leftAICombo; public JComboBox rightAICombo; 

Here's the JComboBox<Object> type parameter, introduced only in java7. If you use jdk below 7 it gives an error

+3
source

Java 7 adds generics to JComboBox . It looks like you are using the JDK version for headphones. Either upgrade to Java 7 or remove the generics. The first is recommended as it offers more features / fixes as well as being updated.

+4
source

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


All Articles