Lightweight interfaces instead of function types
scolebourne at joda.org
Fri Feb 19 10:15:38 PST 2010
On 19 February 2010 17:47, Neal Gafter <neal at gafter.com> wrote:
> Tmp.java:5: [error] generic array creation
> Callable<String> array = new Callable<String>;
> This is a hard error, not a warning.
True. But if I want a Callable<String> I write:
Callable<String> array = new Callable;
This works, and is safe /in practice/ (rather than type-system safe).
> I have problems with your new reference conversions among interface
> types that are not subtypes of each other. They have all of the same
> problems as the lambda conversion that Josh and I are complaining
> about, and more.
Wrapping an anonymous inner class implementing interface B around an
object implementing interface A is a known concept in current Java.
Yes there are downsides (the object identity changes, mitigated by the
equals method rule) but overall, the key is to have a known language
On 19 February 2010 17:55, Mark Thornton <mthornton at optrak.co.uk> wrote:
> Stephen Colebourne wrote:
>> - Requires developers to name everything
> Which still leaves an API like ParallelArray with 81 of them, all with names
> that do little more than repeat the types of their parameters.
Yep. But at least they could be defined in one .java file using just
81 lines of code ;-)
Again, its a trade-off. The benefit for ParallelArray is that
Predicate or Transformer is IMO more meaningful to someone just
casually coming to the API than a random function type.
More information about the lambda-dev