存储Set的问题
场景: 当我从SharedPreferences取出Set实例对象的时候,并且直接使用了它,进行修改,导致此后保存数据的时候后再杀掉App又从中获取的时候,取出来的数据并不是我所预期的。
阅读源码发现:
Note that you <em>must not</em> modify the set instance returned
by this call. The consistency of the stored data is not guaranteed
if you do, nor is your ability to modify the instance at all.
翻译: 注意,不能修改返回的集合实例这个调用。如果您这样做了,存储数据的一致性得不到保证,也不是你的能力来修改的实例。