invocation type of method reference declaration

Dan Smith daniel.smith at oracle.com
Thu Feb 13 16:31:27 PST 2014


On Feb 12, 2014, at 6:00 PM, Rafkind, Jon <jon.rafkind at hp.com> wrote:

> What is the invocation type of the compile-time chosen method
> declaration of a method reference?
> 
> In section 15.3.2:
> The return type of the function type is R; the result of applying
> capture conversion (5.1.10) to the return type of the invocation type
> (15.12.2.6) of the chosen declaration is R', where R is the target type
> that may be used to infer R'; neither R nor R' is void; and R' is
> compatible with R in an assignment context.
> 
> Also in section 18.2.1.2:
> Otherwise, let R be the return type of the function type, and let R' be
> the result of applying capture conversion (5.1.10) to the return type of
> the invocation type (15.12.2.6) of the chosen declaration. If R' is
> void, the constraint reduces to false; otherwise, the constraint reduces
> to ⟨R' → R⟩.
> 
> A method reference is not the same as a method invocation so 15.12.2.6
> don't seem to apply. Are the parameters of the function type supposed to
> act as the types of the argument expressions to the compile-time
> declaration?

There is admittedly a degree of informality here (consistent with the style of the rest of JLS), but I'm not seeing any particular points that need clarification.  (Feel free to point them out if you think I'm missing something.)

The following terms are a bit fuzzy, but have only one reasonable interpretation:

- The "explicit type arguments" of the "method invocation".  Of course this refers to the type arguments of the method reference, a pattern already established in 15.13.1.

- Whether "unchecked conversion was necessary for the method to be applicable".  The applicability test is as described in 15.12.2.2-15.12.2.5, as applied from 15.13.1.

- The "type that was searched" is defined in 15.13.1.

- During inference, we need to know whether "the invocation is a poly expression" (18.5.2).  This is probably the least well-defined.  The rules for whether a method invocation is a poly expression are in 15.12; analogous rules can be applied to the method reference in order to decide whether that particular branch in 18.5.2 should be pursued or not (specifically: the method reference does not have type arguments, the compile-time declaration is generic, and the return type of the compile-time declaration mentions one of its type parameters).

I'll create a bug to clarify that last point in the future.

—Dan


More information about the lambda-spec-observers mailing list