读书人

怎么让你的list不被修改

发布时间: 2012-09-09 09:27:54 作者: rapoo

如何让你的list不被修改
今天在看QuickSearchBox的源码:发现了可以对list的限制,不让list被修改:

 private List<Corpus> mEnabledCorpora;mEnabledCorpora = Collections.unmodifiableList(mEnabledCorpora);


官方文档写:
public static List<E> unmodifiableList (List<? extends E> list)

Since: API Level 1
Returns a wrapper on the specified list which throws an UnsupportedOperationException whenever an attempt is made to modify the list.
Parameters
listthe list to wrap in an unmodifiable list.
Returns
an unmodifiable List.

读书人网 >移动开发

热点推荐