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 | */
|
---|
23 |
|
---|
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 | */
|
---|
33 |
|
---|
34 | public class QualifiedThisExactMatch {
|
---|
35 |
|
---|
36 | void test() throws Exception {}
|
---|
37 |
|
---|
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 | }
|
---|
48 |
|
---|
49 | //---
|
---|
50 |
|
---|
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 | }
|
---|
58 |
|
---|
59 | void check(Object x, Object y) throws Exception {
|
---|
60 | if (x != y) {
|
---|
61 | throw new Exception("named");
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | void checkIt2 () throws Exception {
|
---|
66 | A a = new A();
|
---|
67 | A.B b = a.new B();
|
---|
68 |
|
---|
69 | check(a, a.getThisA());
|
---|
70 | check(a, b.getThisA());
|
---|
71 | check(b, b.getThisB());
|
---|
72 | }
|
---|
73 |
|
---|
74 | //---
|
---|
75 |
|
---|
76 | public static void main(String[] s) throws Exception {
|
---|
77 | QualifiedThisExactMatch x = new QualifiedThisExactMatch();
|
---|
78 | x.checkIt1();
|
---|
79 | x.checkIt2();
|
---|
80 | }
|
---|
81 | }
|
---|