2013-06-21 66 views
4

我有我的項目在Java中的代碼,其中一個類如下所示,但是當我想運行此代碼時,我將在此類中得到編譯錯誤代碼的一部分是:JComboBox類型不是通用的;它不能被參數化參數<Object>

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>

問題是什麼?

回答

3

更改以下行

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

在java7介紹

public JComboBox leftAICombo; 
public JComboBox rightAICombo; 

這裏JComboBox<Object>類型參數only.if您使用以下7 JDK提示錯誤

4

泛型加入JComboBox在Java 7中。看起來您正在使用JDK的初始版本。升級到Java 7或刪除泛型。前者是推薦的,因爲它提供了更多的功能/修復以及最新的。

相關問題