I think the idea is giving a subset of the Set methods that are read-only. Any write operations wouldn't be available on the interface, so you couldn't compile it.
On 23 March 2017 at 08:37, sebb <seb...@gmail.com> wrote: > On 23 March 2017 at 07:48, Lukasz Lenart <lukaszlen...@apache.org> wrote: > > Hi, > > > > I see that the Collections4 provides those classes. Anyway I wonder > > why I the constructor is private and why the factory method > > unmodifiableSet() returns Set? > > > > I would love to use those classes directly, to be straightforward that > > I expect the UnmodifiableSet and not just a Set. > > > > What about adding a method like in Guava? Something like this: > > > > public static UnmodifiableSet of(Set<T> set) > > > > This allows define UnmodifiableSets in code and use compiler to check > > if everything is ok. > > Not sure I follow. > > What exactly can the compiler check? > > The API for UnmodifiableSet is basically the same as the API for Set. > > Yes, it implements Unmodifiable, but that is a Collections4 class and > means nothing to the compiler. > > It is only at run-time that the the classes throw an error for update > operations. > > > > > Regards > > -- > > Ćukasz > > + 48 606 323 122 http://www.lenart.org.pl/ > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > > For additional commands, e-mail: dev-h...@commons.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > > -- Matt Sicker <boa...@gmail.com>