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

Java 错误消息:类型StudentList不接受参数,java,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) {

我正在尝试编译和测试此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);
    }

}
import java.io.*;
导入java.util.*;
导入java.util.LinkedList;
公开课
{
公共静态void main(字符串[]args)
{
StudentList ilist=newstudentlist();
StudentList slist=newstudentlist();
字符串s;
整数i;
扫描仪输入=新扫描仪(系统输入);
System.out.print(“请输入要提供的单词(\'stop\'停止):\t”);
while(在.hasNext()中){
s=in.next();
如果(s.equalsIgnoreCase(“stop”){break;}
报价单;
System.out.println(“大小为:”+slist.Size());
System.out.print(“请输入要提供的单词(\'stop\'tostop):\t”);
}
System.out.println(“\n”+slist);
字符串si=slist.peek();
System.out.println(“测试peek():”+si);
System.out.print(“请输入一个整数以提供(停止):\t”);
while(在.hasNextInt()中){
i=in.nextInt();
ilist.要约(i);
System.out.println(“大小为:+ilist.Size());
System.out.print(“请输入一个整数以提供(停止):\t”);
}
System.out.println(“\n”+ilist);
int pi=ilist.peek();
System.out.println(“测试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>( );
                                                       ^
OfferDriver.java:16:错误:类型StudentList不接受参数
StudentList ilist=newstudentlist();
^
java:16:错误:类型StudentList不接受参数
StudentList ilist=newstudentlist();
^
java:17:错误:类型StudentList不接受参数
StudentList slist=newstudentlist();
^
java:17:错误:类型StudentList不接受参数
StudentList slist=newstudentlist();
^

请注意StudentList.java是一项正在进行的工作,我的意思是现在只测试方法offer()。感谢您提供的所有帮助

如果您想让
类接受类型参数,请像这样修改
学生列表

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;
}


}
import java.io.*;
导入java.util.*;
公共类学生列表扩展了LinkedList
{
私有int newInt;
私有布尔newE;
公立学生名单(){
超级();
}
公立学生名单(int i、布尔e){
newInt=i;
newE=e;
}
公共布尔报价(布尔e){
返回e;
}
}

您的类定义错误。 请注意以下课堂声明:

public class StudentList<T> extends LinkedList <T>
公共类学生列表扩展了LinkedList

编译器错误是不言自明的。您的StudentList类没有类型参数那么我应该使用什么作为类型参数?见下面的答案。为什么您创建了单独的StudentList类而不是直接使用LinkedList?如果我这样做,在编译时将找不到符号T,我会收到一条新的错误消息OfferDriver.java:16:error:class StudentList中的构造函数StudentList无法应用于给定的类型;StudentList ilist=新建StudentList();^必需:int,boolean found:无参数原因:实际参数列表和形式参数列表长度不同,其中T是类型变量:T extends class StudentList中声明的对象
您必须提供默认构造函数,因为您提供了一个参数化的构造函数。见更新answer@GEARZ这真的不难理解。你试过了吗?
StudentList
类中没有带任何参数的构造函数。