Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28425

Re: String[] , Arrays.asList , Collections.unmodifiableList

From Stanimir Stamenkov <s7an10@netscape.net>
Newsgroups comp.lang.java.programmer
Subject Re: String[] , Arrays.asList , Collections.unmodifiableList
Date 2014-05-11 00:09 +0300
Organization A noiseless patient Spider
Message-ID <lkm4hk$uad$1@dont-email.me> (permalink)
References <bslom95b4j4s6eh4m5lfj6d3mq49uitlb3@4ax.com>

Show all headers | View raw


Thu, 08 May 2014 21:30:08 -0700, /Roedy Green/:

> We have to use Collections.unmodifiableList which gives us a
> Collections.unmodifiableList wrapper around our List that throws
> UnsupportedOperationException when we attempt to write.
>
> The catch is the set methods are still there. We don't find out about
> the problem of modifying this list until run time.

I think this more or less a general rule: Don't assume a returned 
Collection (or Map) is mutable unless explicitly stated by the 
documentation / contract.

-- 
Stanimir

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

String[] , Arrays.asList , Collections.unmodifiableList Roedy Green <see_website@mindprod.com.invalid> - 2014-05-08 21:30 -0700
  Re: String[] , Arrays.asList , Collections.unmodifiableList leif.roar@invalid.com (Leif Roar Moldskred) - 2014-05-09 01:02 -0500
    Re: String[] , Arrays.asList , Collections.unmodifiableList Roedy Green <see_website@mindprod.com.invalid> - 2014-05-09 09:25 -0700
      Re: String[] , Arrays.asList , Collections.unmodifiableList leif.roar@invalid.com (Leif Roar Moldskred) - 2014-05-09 12:45 -0500
  Re: String[] , Arrays.asList , Collections.unmodifiableList Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-11 00:09 +0300

csiph-web