list literal gotcha and suggestion
Ola Bini
ola.bini at gmail.com
Thu Oct 8 01:09:17 PDT 2009
Kai Kunstmann wrote:
> Am Mittwoch, den 07.10.2009, 17:46 -0700 schrieb Lawrence Kesteloot:
>>> http://www.google.com/codesearch?hl=en&lr=&q=ImmutableList.of|ImmutaleSet.of|ImmutableMap.of|Arrays.asList\(\w%2B,\w%2B+lang:java&sbtn=Search
>>>
>>> Seems like all sorts of configuration/static data/quick and
>>> dirty/unittest/mock/etc types of syntax would benefit.
>> That search returns 800 files out of a total of 11,300,000. That's one
>> file in 14,125, or 0.007%.
>>
>> I would be against a feature which (1) has such an unclear correct
>> specification; (2) provides so little advantage over a static
>> ArrayList.of() and HashSet.of(); and (3) helps only one file in
>> 14,125.
>>
>> On the other hand, the idea (proposed twice in this discussion) of
>> have a pair literal seems much more widely useful, and would allow
>> HashMap.of().
>
>
> A struct-like tuple literal of any arbitrary (immutable) size would
> cover even more use-cases, e.g. multiple return values in methods.
Not necessarily. Tuples are generally not iteratable (Python being the
exception). Also they don't actually match Collection<T> since they have
several different types. Tuples doesn't really solve any of the
problems, and they would have to have different semantics than existing
collections, which means larger incisions in the language.
Cheers
--
Ola Bini (http://olabini.com)
Ioke creator (http://ioke.org)
JRuby Core Developer (http://jruby.org)
Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
Practical JRuby on Rails (http://apress.com/book/view/9781590598818)
"Yields falsehood when quined" yields falsehood when quined.
More information about the coin-dev
mailing list