我有一个 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;
Run Code Online (Sandbox Code Playgroud)
错误来自两行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;
Run Code Online (Sandbox Code Playgroud)
到
public JComboBox leftAICombo;
public JComboBox rightAICombo;
Run Code Online (Sandbox Code Playgroud)
这里仅 JComboBox<Object>在 java7 中引入了类型参数。如果您使用的是低于 7 的 jdk,则会出现错误
| 归档时间: |
|
| 查看次数: |
3785 次 |
| 最近记录: |