错误消息:类型StudentList不接受参数

时间:2014-09-07 04:23:30

标签: java

我正在尝试编译和测试这个LinkedList类型,但是当我这样做时,我收到一条错误消息。我的StudentList.java代码如下

import java.io.*;
import java.util.*;

public class StudentList extends LinkedList
{
    private int newInt;
    private boolean newE;
    public StudentList(int i, boolean e) {
        newInt = i;
        newE = e;
}

public boolean offer(boolean e) {
       return e;
}


}

当我编译OfferDrive.java文件时,如下所示:

import java.io.*;
import java.util.*;
import java.util.LinkedList;

public class OfferDriver
{
    public static void main ( String[] args)
    {
            StudentList<Integer> ilist = new StudentList<Integer>( );
            StudentList<String> slist = new StudentList<String>( );

            String s;
            Integer i;
            Scanner in = new Scanner(System.in);
            System.out.print("Please enter a word to offer (\"stop\" to stop):\t");
            while (in.hasNext()) {
                    s = in.next();
                    if (s.equalsIgnoreCase("stop")) { break; }
                    slist.offer(s);
                    System.out.println("Size is: " + slist.size());
                    System.out.print("Please enter a word to offer(\"stop\"tostop):\t");
            }
            System.out.println("\n" + slist);
            String si = slist.peek();
            System.out.println("Testing peek(): " + si);

            System.out.print("Please enter an integer to offer (<any word> to stop):\t");
            while (in.hasNextInt()) {
                    i = in.nextInt();
                    ilist.offer(i);
                    System.out.println("Size is: " + ilist.size());
                    System.out.print("Please enter an integer to offer (<any word> to stop):\t");
            }
            System.out.println("\n" + ilist);
            int pi = ilist.peek();
            System.out.println("Testing peek(): " + pi);
    }

}

我收到此错误代码

OfferDriver.java:16: error: type StudentList does not take parameters
                StudentList<Integer> ilist = new StudentList<Integer>( );
                       ^
OfferDriver.java:16: error: type StudentList does not take parameters
                StudentList<Integer> ilist = new StudentList<Integer>( );
                                                        ^
OfferDriver.java:17: error: type StudentList does not take parameters
                StudentList<String> slist = new StudentList<String>( );
                       ^
OfferDriver.java:17: error: type StudentList does not take parameters
                StudentList<String> slist = new StudentList<String>( );
                                                       ^

请注意,StudentList.java正在进行中,我的意思是此时只测试方法offer()。感谢您的帮助

2 个答案:

答案 0 :(得分:0)

如果您希望它采用类型参数

,请

修改您的StudentList

import java.io.*;
import java.util.*;

public class StudentList<T> extends LinkedList<T>
{
private int newInt;
private boolean newE;

public StudentList(){
   super();
}
public StudentList(int i, boolean e) {
    newInt = i;
    newE = e;
}

public boolean offer(boolean e) {
   return e;
}


}

答案 1 :(得分:0)

你的班级定义错了。 请注意以下课程声明:

public class StudentList<T> extends LinkedList <T>