How do I find cycles in my object hierarchy?
问题 There is a class Company , which has reference to another instance of Company to represent the parent . Lets say there are four companies c1 , c2 , c3 & c4 and c2 , c3 , c4 has parent company set as c1 . For example: public class Company { public Company parent; public Company() { } public Company(Company parent) { this.parent = parent; } public static void main(String[] args) { Company c1 = new Company(); Company c2 = new Company(c1); Company c3 = new Company(c1); Company c4 = new Company(c1