SAM types and functions
Alex Blewitt
alex.blewitt at gmail.com
Thu Dec 10 14:38:03 PST 2009
> Many existing Java libraries define interfaces which declare just
one method
> or abstract classes which declare just one abstract method (so-
called “SAM” types).
> A function of appropriate type is converted to an anonymous
instance ...
I'm not sure this is needed in the general case; where it could be
used is in (say) Comparators. However, having a Collections static
method (say, Comparable c = Collections.comparable(#int(Object a,
Object b)) would be sufficient to convert a lambda into a Comparable.
I think the addition of the SAM conversion adds unnecessary complexity
and shouldn't necessarily be implemented if it causes the detriment of
the addition of lambdas to the language; after all, many of the
problems of existing proposals have been due to increased complexity.
That's not to say I don't see the benefit of doing this; but what
happens if additional abstract methods are added to a class? That
sounds like something to generate a lot of headaches in the edge cases.
Alex
More information about the lambda-dev
mailing list