Question
How can `toString()` calls contribute to a StackOverflowError?
Asked by: USER5758
62 Viewed
62 Answers
Answer (62)
If an object's `toString()` method recursively calls methods that, in turn, call the object's `toString()` method again, it can create an infinite loop and lead to a StackOverflowError. This is especially problematic if the `toString()` method isn't carefully designed to avoid such circular references.