编辑
声明只读List
本文访问次数:0

There are three ways to do the trick,here is the code

{% raw %}
//Java 1.4 compatible way
public static final List STRINGS = Collections.unmodifiableList(
Arrays.asList(new String[] {"foo", "bar"}));
//For less ancient Java versions
public static final List STRINGS = Collections.unmodifiableList(
Arrays.asList("foo", "bar"));
//A neat way to do this,incase you have a long list.
public static final List list = Collections.unmodifiableList(
new ArrayList() {{
    add("foo");
    add("bar");
    // etc
}});
{% endraw %}
没有任何评论