Variable number of parameters

Stephen Colebourne scolebourne at joda.org
Tue Dec 6 01:55:31 PST 2011


On 6 December 2011 01:37, Brian Goetz <brian.goetz at oracle.com> wrote:
> I don't think we'll be doing that.  As you point out, it interferes with
> target type inference.  (What you suggest is more natural in a functional
> language where tuples are subtyped inclusively (i.e., Tuple(T,U) <:
> Tuple(T,U,V)), and where argument list are treated as tuples.  But that's a
> pretty foreign concept in Java.)  In any case, I don't think this feature
> pulls its weight.  Saying (v, i) -> ... is just not that much more typing
> than (v) -> ...
>
> What we did consider was allowing the use site to omit *all* the parameters
> when they are unneeded, such as is common with certain event listener APIs
> where the parameters carry information that is not always needed.  (Think of
> this as inferring the arity.)  Though this was a better intuitive match with
> the syntax that supported the #{ ... } nilary syntax than it is with the
> current () -> {} syntax.

I don't have strong feelings for the feature, but am concerned about
the impact on the APIs without it.

Most of the various API methods added to list could arguably want to
know the index, which doubles the number of methods. Instead, we'll
probably have to do without index access, which will be as much of a
pain in certain use cases as the foreach loop is now.

As always, its a trade-off.
Stephen


More information about the lambda-dev mailing list