Lista类型不是通用的;我的清单是对的?

时间:2017-04-04 23:20:02

标签: java

我遇到了一些问题:错误

Lista类型不是通用的;它不能用参数"整数"

参数化

我的文件测试:

public class testy {

public static void main(String[] args) {
    Lista<Integer> l = new Lista<Integer>();
    l.add(5);
    l.add(7);
    //System.out.println(l.removeFirst());
}
}

列表:

public class Lista implements Serializable{

ListaS<T> Lista;

public Lista() {
    Lista = new ListaS<T>(null, Lista, Lista);
    Lista.setNext(Lista);
    Lista.setPrevious(Lista);
}

 public int Rozmiar(){
     int counter = 0;
     if(nastepny == null)
          return counter;
      else{
          ListaS<T> tmp = counter;
          do{
              next = next.wezNastepny();
              counter++;
            }while(tmp != previous);
        }
        return counter;
    }

    public boolean Empty(){
        if(Size()== 0 )
            return true;
        else
            return false;
    }

    public void addStart(T wartosc){
        ListaS<T> nowy = new ListaS<T>(wartosc);
        if(next == null){
            next=newnode;
            next=newnode;
            nowy.setNext(null);
            nowy.setPrevious(null);
        }else{
            nowy.setNext(nastepny);
            next.setPrevious(nowy);
            next = nowy;
        }       
    }

    public void addEnd(T wartosc){
        ListS<T> nowy = new ListaS<T>(value);
        if(previous == null){
            next=nowy;
            previous =nowy;
            newnode.setNext(null);
            newnode.setPrevious(null);
        }else{
            newnode.setPrevious(previous);
            previous.setNext(nowy);
            previous=nowy;
        }
    public E removeFirst() {
        if (size == 0) throw new NoSuchElementException();
        ListS tmp = next;
        next = next.getNext();
        next.setNext = null;
        System.out.println("deleted: "+tmp.value);
        return tmp.wezWartosc();
    }
}

最后一个

 public class ListaS<T> implements Serializable{
 T value;
 ListaS<T> next;
 ListaS<T> previous;

ListaS(T value, ListaS<T> next, ListaS<T> poprzedni) {
    this.value = value;
    this.next = next;
    this.previous = previous;
}

T getValue() {
    return value;
}
public void setNext(ListaS<T> nastepny) {
    this.next = next;
}
public ListaS<T> getPrevious() {
    return previous;
}
public void setPrevious(ListaS<T> poprzedni) {
    this.previous = previous;
}
public void setValue(T value) {
    this.value = value;
}
public ListaS<T> getNext() {
    return next;
}
}

好的,如果我们解决第一个问题可以有人告诉我我的功能还可以吗? 我应该怎么写removeLast()?

1 个答案:

答案 0 :(得分:1)

只需转换Lista

中的public class Lista<T> implements Serializable班级定义即可