Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anything bad happen if an array(list) contains itself?

Tags:

java

I noticed that if I do something like:

ArrayList anArray = new ArrayList();
anArray.add(anArray);

Netbeans auto-compiler doesn't seem to have any problem with it and I still seem to be able to reference everything. Are there any bad side effects of doing this?

like image 810
user2457072 Avatar asked Jun 20 '13 18:06

user2457072


1 Answers

I doubt anything bad would happen in most cases.

The problem would come if you were processing the list recursively in which case you'd end up with a stack overflow.

like image 119
wobblycogs Avatar answered Sep 27 '22 20:09

wobblycogs