我有一个常量映射,如下所示:privatestaticMap_typesMap=newHashMap(){{put("string",'S');put("normalizedString",'N');put("token",'T');//(...)}我真的需要使用Collections.unmodifiableMap()来创建这个map吗?使用它有什么好处?不使用它有什么缺点,除了它们并没有真正变得恒定之外? 最佳答案 Collections.unmodifiableMap保证map不会被修改。如果您想从方法调用返回内部映射的只读V
如果我写Lista1=Arrays.asList(1,2,3);Lista2=Collections.unmodifiableList(a1);a2是只读的,但如果我写了a1.set(0,10);那么a2也被修改了。如果在API中说:Returnsanunmodifiableviewofthespecifiedcollection.Thismethodallowsmodulestoprovideuserswith"read-only"accesstointernalcollections.那么,为什么如果我修改了原始集合,目标复制的集合也被修改了?也许我误解了它的意思,如果是这样,有什
如果我写Lista1=Arrays.asList(1,2,3);Lista2=Collections.unmodifiableList(a1);a2是只读的,但如果我写了a1.set(0,10);那么a2也被修改了。如果在API中说:Returnsanunmodifiableviewofthespecifiedcollection.Thismethodallowsmodulestoprovideuserswith"read-only"accesstointernalcollections.那么,为什么如果我修改了原始集合,目标复制的集合也被修改了?也许我误解了它的意思,如果是这样,有什
我在StatelessWidget中有一个ListView。它有项目,每个项目都包含一个复选框。当有人检查一个项目时,我希望ListView将其作为参数发送到另一个页面。但是当我这样做时,它给了我这个错误:I/flutter(7067):ThefollowingUnsupportedErrorwasthrownwhilehandlingagesture:I/flutter(7067):Unsupportedoperation:CannotaddtoanunmodifiablelistI/flutter(7067):Whentheexceptionwasthrown,thiswasthe