将<e>分配给字符串</e>

时间:2015-03-23 15:31:30

标签: java linked-list tostring

嗨,每当我尝试编译它时,我总是会收到错误,说我不能将E分配给String。请帮我解决一下这个。谢谢

public String toString() {
     ListNode<E> start = head;
      String result = "";
      if (numNodes == 1) {
          result = start.getElement();
      }
      else {
          for (int i = 0; i<numNodes-2; i++) {
              result = result + start.getElement();
              start = start.getNext();
          }
      result = result + start.getElement();
      }
  }

1 个答案:

答案 0 :(得分:0)

使用String.valueOf(Val)将对象转换为字符串