是的,会有循环引用的问题。Item类中的father属性引用了Demo类,而Demo类中的items属性又引用了Item类,因此存在循环引用。

class Item {
 String name;
 int age;
 Demo father;
 Item(this.name, this.age, this.father);
}

class Demo{
 
 Map<String, Item> items = {};
 
 addItem(String key, String name, int age) {
 items[key] = Item(name, age, this);
 }
 
}

以上代码会有循环引用的问题吗

原文地址: https://www.cveoy.top/t/topic/w70 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录