嗨,每当我尝试编译它时,我总是会收到错误,说我不能将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();
}
}
答案 0 :(得分:0)
使用String.valueOf(Val)将对象转换为字符串