I just want to create an object of class, but got this error when debugging. Can anybody tell me what the problem is? The location of this code is in some Spring(2.5) Servic
For me the same exception was thrown when the toString was defined as such:
@Override
public String toString() {
return "ListElem [next=" + next + ", data=" + data + "]";
}
Where ListElem is a linked list element and I created a ListElem as such:
private ListElem cyclicLinkedList = new ListElem<>(3);
ListElem cyclicObj = new ListElem<>(4);
...
cyclicLinkedList.setNext(new ListElem(2)).setNext(cyclicObj)
.setNext(new ListElem(6)).setNext(new ListElem(2)).setNext(cyclicObj);
This effectively caused a cyclic linked list that cannot be printed. Thanks for the pointer.