如何让你的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
list the list to wrap in an unmodifiable list.
Returns
an unmodifiable List.

你可能感兴趣的:(list)