alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (MethodReference37.java)

This example Java source code file (MethodReference37.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

inner::new, methodreference37, outer, sam1, sam2

The MethodReference37.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  spurious exceptions when checking references to inner constructors where
 *          the enclosing class is not defined in any outer context
 * @compile/fail/ref=MethodReference37.out -XDrawDiagnostics MethodReference37.java
 */

class MethodReference37 {

    interface SAM1<R> {
        R invoke();
    }

    interface SAM2<R, A> {
        R invoke(A a);
    }

    static class Outer {
        class Inner { }

        static void test1() {
            SAM2<Inner, Outer> sam = Inner::new;
        }

        void test2() {
            SAM1<Inner> sam0 = Inner::new;
            SAM2<Inner, Outer> sam1 = Inner::new;
        }
    }

    static void test1() {
        SAM2<Outer.Inner, Outer> sam = Outer.Inner::new;
    }

    void test2() {
        SAM2<Outer.Inner, Outer> sam1 = Outer.Inner::new;
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java MethodReference37.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.