Method Pointers

Stephen Colebourne scolebourne at
Sun Feb 26 15:02:26 PST 2012

On 26 February 2012 22:30, Brian Goetz <brian.goetz at> wrote:
> Good question.  Agreed that all things being equal, this would be a
> desirable property.
> Unfortunately, guarantees like this come with a possibly significant
> cost, and the question comes down to: how much are we willing to pay for
> properties like this?
> Where things are currently is that the identity properties of SAM
> conversion are deliberately underspecified, to maximize flexibility /
> minimize costs for the runtime.  The current implementation makes some
> attempts to fold together identical method references and lambdas, but
> does not make "heroic efforts" to do so.
> If you want identity equality for bound method references (this::name),
> this turns out to be extremely expensive; we would have to keep an
> interned table of captured "method m bound to receiver r" method
> references, using weak references to keep this table from causing memory
> leaks.  Are we willing to pay that much in capture cost, implementation
> complexity, and dynamic footprint to preserve the property you are
> asking for?  (This seems a pretty clear "no" to me; this is one of those
> properties that provides a small benefit for a few but a significant
> cost for everyone.)
> One weaker and less expensive option would be to provide this guarantee
> for unbound and static references only (though this is by no means
> free); another would be to commit only to making the two objects .equals
> to each other rather than identity-equals.  This is under consideration,
> but even this may be cost-prohibitive and/or too full of holes to
> provide a sufficiently intuitive semantics to make it worth it.

Have you considered (I'm sure you have...) a form of requesting the
reference to have equals semantics? Some form of method call or
wrapper  that the user muist specifically use to get the equals or ==

I think that a manual extra step would be fine on the user-side. I've
no specific thoughts about whether it helps implementation beyond
noting that it bounds the hash map you describe.


More information about the lambda-dev mailing list