我有一个 Java 项目代码,其中一个类如下所示,但是当我想运行这段代码时,我会在这个类中遇到编译错误,其中一部分代码是:
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;
错误来自两行public JComboBox<Object> leftAICombo;
和 public JComboBox<Object> rightAICombo;
错误是:
The type JComboBox is not generic; it cannot be parameterized with arguments <Object>
问题是什么?
最佳答案
改变下面几行
public JComboBox<Object> leftAICombo;
public JComboBox<Object> rightAICombo;
到
public JComboBox leftAICombo;
public JComboBox rightAICombo;
在这里JComboBox<Object>
仅在 java7 中引入的类型参数。如果您使用低于 7 的 jdk,则会出错
关于java - JComboBox 类型不是通用的;它不能用参数 <Object> 参数化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17234558/