jdk/test/java/lang/invoke/lambda/LambdaClassFinal.java
author jbachorik
Tue, 21 Jan 2014 13:04:55 +0100
changeset 22353 d09e3ff5fd63
parent 16859 45fbee947921
permissions -rw-r--r--
8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16859
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     1
/*
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     4
 *
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     8
 *
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    13
 * accompanied this code).
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    14
 *
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    18
 *
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    21
 * questions.
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    22
 */
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    23
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    24
/*
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    25
 * @test
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    26
 * @bug 8012028
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    27
 * @summary Generated Lambda implementing class should be final
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    28
 */
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    29
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    30
import java.lang.reflect.Modifier;
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    31
import java.io.Serializable;
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    32
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    33
public class LambdaClassFinal {
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    34
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    35
    interface I {
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    36
        void m();
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    37
    }
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    38
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    39
    interface Iser extends Serializable {
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    40
        void m();
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    41
    }
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    42
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    43
    static void assertTrue(boolean cond) {
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    44
        if (!cond)
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    45
            throw new AssertionError();
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    46
    }
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    47
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    48
    public static void main(String[] args) throws Exception {
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    49
        new LambdaClassFinal().test();
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    50
    }
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    51
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    52
     void test() throws Exception {
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    53
        I lam = () -> { };
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    54
        assertTrue((lam.getClass().getModifiers() & Modifier.FINAL) != 0);
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    55
        Iser slam = () -> { };
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    56
        assertTrue((slam.getClass().getModifiers() & Modifier.FINAL) != 0);
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    57
    }
45fbee947921 8012028: Metafactory-generated lambda classes should be final
rfield
parents:
diff changeset
    58
}