Playing with new compiler
Robert
robert.field at oracle.com
Wed May 25 10:02:05 PDT 2011
Ali Ebrahimi <ali.ebrahimi1781 at gmail.com> wrote:
>Hi Maurizio,
>I play with new compiler and have some questions.
>
>
>public class AMBTest {
> static interface SAM1 {
> String m1(Integer n) throws Exception;
> }
>
> static interface SAM2 {
> void m2(Integer n);
> }
>
> static interface SAM<R,A> {
> R m(A n);
> }
>
> static void call(SAM1 sam) {
> System.out.println("SAM1");
> }
>
> static void call(SAM2 sam) {
> System.out.println("SAM2");
> }
>
> static <R,A> void call(SAM<R,A> sam) {
> System.out.println("SAM");
> }
>
> public static void main(String[] args) {
> call(#{ x -> System.out.println(x); return ""; }); // prints "SAM1"
>
> call(#{ x -> System.out.println(x); return ; }); // prints "SAM2"
>
> call(#{ x -> System.out.println(x);}); /* compile :
>reference to call is ambiguous, both method call(SAM1) in AMBTest and
>method call(SAM2) in AMBTest match
>*/
> call(#{ x -> System.out.println(x); return (Object) null; });
> /*compile error: no suitable method found for call(<lambda>) method
>AMBTest.<R,A>call(SAM<R,A>) is not applicable (cyclic inference - try
>specifying lambda parameter types)
>method AMBTest.call(SAM2) is not applicable (actual argument <lambda>
>cannot be converted to SAM2 by method invocation conversion
>(incompatible return type Object in lambda expression))
>method AMBTest.call(SAM1) is not applicable (actual argument <lambda>
>cannot be converted to SAM1 by method invocation conversion
>(incompatible return type Object in lambda expression))
>where R,A are type-variables:
>R extends Object declared in method <R,A>call(SAM<R,A>)
>A extends Object declared in method <R,A>call(SAM<R,A>)
>
>*/
>
> call(#{ x -> System.out.println(x); return null; }); //prints
>"SAM1" ?????
>
>
>
>}
>}
>
>Are results expected?
>
>Best Regards,
>Ali Ebrahimi
>
More information about the lambda-dev
mailing list