Expected distribution of lambda sizes (Re: Syntax poll, take 2)

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Jun 15 11:05:21 PDT 2011


On 15/06/11 18:43, John Nilsson wrote:
> On Wed, Jun 15, 2011 at 7:39 PM, Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com>  wrote:
>> *) Pair#fst is compatible with a SAM type whose method is m(Pair)
>> *) Pair<>#fst is compatible with a SAM type whose method is of the kind
> Ah, there you go. Forgot about this "interesting" aspect of the type system.
>
> Is it reasonable though? When would it, in practice, be important to
> enforce this difference?
>
> BR,
> John
class Pair<X,Y> {
   X fst() { return null; }
   Y snd() { return null; }
}

interface SAM {
    Integer m(Pair<Integer,String> p);
}

interface RawSAM {
    Object m(Pair p);
}

class Test {

static void call(SAM s) { System.out.println("1"); }
static void call(RawSAM s) { System.out.println("2"); }

public static void main(String[] args) {
    call( Pair<Integer,String>#fst ); //prints 1
    call( Pair#fst ); //prints 2
}

}

Maurizio


More information about the lambda-dev mailing list