test/tools/javac/QualifiedThisExactMatch.java

Wed, 14 Nov 2018 10:18:25 -0800

author
diazhou
date
Wed, 14 Nov 2018 10:18:25 -0800
changeset 3762
7909abb85562
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u201-b04 for changeset a7f48b9dfb82

     1 /*
     2  * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 4102393 4133457
    27  * @summary Verify that <class>.this  matches <class> exactly, not a subclass.
    28  * @author maddox
    29  *
    30  * @run compile QualifiedThisExactMatch.java
    31  * @run main QualifiedThisExactMatch
    32  */
    34 public class QualifiedThisExactMatch {
    36     void test() throws Exception {}
    38     void checkIt1() throws Exception {
    39         QualifiedThisExactMatch z = new QualifiedThisExactMatch() {
    40             void test() throws Exception {
    41                 if (this == QualifiedThisExactMatch.this) {
    42                     throw new Exception("anonymous");
    43                 }
    44             }
    45         };
    46         z.test();
    47     }
    49     //---
    51     class A  {
    52         Object getThisA() { return A.this; }
    53         class B extends A {
    54             Object getThisA() { return A.this; }
    55             Object getThisB() { return B.this; }
    56         }
    57     }
    59     void check(Object x, Object y) throws Exception {
    60         if (x != y) {
    61             throw new Exception("named");
    62         }
    63     }
    65     void checkIt2 () throws Exception {
    66         A a = new A();
    67         A.B b = a.new B();
    69         check(a, a.getThisA());
    70         check(a, b.getThisA());
    71         check(b, b.getThisB());
    72     }
    74     //---
    76     public static void main(String[] s) throws Exception {
    77         QualifiedThisExactMatch x = new QualifiedThisExactMatch();
    78         x.checkIt1();
    79         x.checkIt2();
    80     }
    81 }

mercurial