hg: lambda/lambda/langtools: Enhance most specific check to take into account structural type info
maurizio.cimadamore at oracle.com
maurizio.cimadamore at oracle.com
Fri Mar 23 08:00:28 PDT 2012
Changeset: b949ff379c06
Author: mcimadamore
Date: 2012-03-23 15:00 +0000
URL: http://hg.openjdk.java.net/lambda/lambda/langtools/rev/b949ff379c06
Enhance most specific check to take into account structural type info
This extension to the most specific algorithm allows the compiler to disambiguate between applicable candidates with different return/arguments/thrown types. Consider the following example:
interface SAM1 {
int m();
}
interface SAM2 {
long m();
}
void m(SAM1 s1) { ... }
void m(SAM2 s2 { ... }
m(()->1);
The compiler here detects two potentially applicable methods m(SAM1) and m(SAM2). The formal argument types are unrelated, as neither SAM1 <: SAM2 nor SAM2 <: SAM1. However, the compiler can look at the underlying functional descriptor, and pick m(SAM1) since the return type of SAM1's functional descriptor is 'more specific' than the one of SAM2.
This enhanced logic only apply if standard most specific logic fails AND if the corresponding actual argument is a structural poly expression (lambda/method reference).
! src/share/classes/com/sun/tools/javac/comp/Resolve.java
+ test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java
! test/tools/javac/lambda/sqe/lambdaExpression/SamConversionComboTest.java
More information about the lambda-dev
mailing list