JEP 186: Collection Literals
Per Bothner
per at bothner.com
Tue Jan 21 12:53:29 PST 2014
On 01/21/2014 11:39 AM, Brian Goetz wrote:
> So, there's been some good discussion regarding the proper scope of
> Collection Literals, so let me summarize what I heard. I am sensing
> that the center of gravity is roughly behind these points:
I'm good with your summary, though I'd add one note:
> 2. Having these literals be mutable would be surprising.
I think it depend on the target type - whether it's explicit or implicit.
For example:
ArrayList<String> s1 = {"a", "b" };
List<String> s2 = {"a", "b" };
I think if a concrete type is the target, then that controls
mutability. If the target is an interface, then we should infer
a "default implementation class" - which should be immutable, at
least for any builtin support. One way to specify this:
public interface List<T> extends ... {
public static final Class DEFAULT_CLASS_FOR_LITERAL =
ImmutableArrayList.class;
...
}
--
--Per Bothner
per at bothner.com http://per.bothner.com/
More information about the lambda-dev
mailing list