@SuppressWarnings("未选中&#34)

时间:2016-05-25 17:43:03

标签: java compiler-warnings singly-linked-list

我正在编写Singly链表的基本代码,发现存在编译错误,必须使用@SuppressWarnings("未经检查")来摆脱它。

我想知道造成这个未检查错误的原因是什么?谢谢。

public class SinglyLinkedList1<T> {

  private class Node<T>{
    private T data;
    private Node next;
    public Node (T item, Node<T> next) {
      this.data = item;
      this.next = next;
    }
    public Node (T item) {
      this.data = item;
      this.next = null;
    }
  }

  private Node<T> head;

  public SinglyLinkedList1() {
    this.head = null;
  }

  public void add(T item) {
    if (head == null) {
      head = new Node<T>(item);
    } else {
      head.next= new Node<T>(item);
    }
  }


  @SuppressWarnings("unchecked")
  public void print() {
    if (head == null) {
      System.out.println("null");
    } else {
      Node<T> current = head;
      while (current != null) {
        System.out.println("data: " + current.data);
        current = current.next;
      }
    }
  } 


  public static void main(String[] args) {
    SinglyLinkedList1<Integer> List1= new SinglyLinkedList1<Integer> ();
    List1.add(1);
    List1.print();
  }

}

0 个答案:

没有答案