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

Java example source code file (LambdaConv09.java)

This example Java source code file (LambdaConv09.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

foo1, foo2, foo3, foo4, foo5, foo6, foo7, lambdaconv09, string

The LambdaConv09.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that SAM conversion handles Object members correctly
 * @author  Alex Buckley
 * @author  Maurizio Cimadamore
 * @compile/fail/ref=LambdaConv09.out -XDrawDiagnostics LambdaConv09.java
 */

class LambdaConv09 {

    // Not a SAM type; not enough abstract methods
    interface Foo1 {}

    // SAM type; Foo has no abstract methods
    interface Foo2 { boolean equals(Object object); }


    // Not a SAM type; Foo still has no abstract methods
    interface Foo3 extends Foo2 { public abstract String toString(); }

    // SAM type; Bar has one abstract non-Object method
    interface Foo4<T> extends Foo2 { int compare(T o1, T o2); }

    // Not a SAM type; still no valid abstract methods
    interface Foo5 {
        boolean equals(Object object);
        String toString();
    }

    // SAM type; Foo6 has one abstract non-Object method
    interface Foo6<T> {
        boolean equals(Object obj);
        int compare(T o1, T o2);
    }

    // SAM type; Foo6 has one abstract non-Object method
    interface Foo7<T> extends Foo2, Foo6 { }

    void test() {
        Foo1 f1 = ()-> { };
        Foo2 f2 = ()-> { };
        Foo3 f3 = x -> true;
        Foo4 f4 = (x, y) -> 1;
        Foo5 f5 = x -> true;
        Foo6 f6 = (x, y) -> 1;
        Foo7 f7 = (x, y) -> 1;
    }
}

Other Java examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.