This example Java source code file (NestedTypes.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.
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.annotation.*;
import java.util.Map;
/*
* @test
* @bug 8006775
* @summary new type annotation location: nested types
* @author Werner Dietl
* @compile NestedTypes.java
*/
class Outer {
class Inner {
class Inner2 {
// m1a-c all have the same parameter type.
void m1a(@A Inner2 p1a) {}
void m1b(Inner.@A Inner2 p1b) {}
void m1c(Outer.Inner.@A Inner2 p1c) {}
// notice the difference to m1d
void m1d(@A Outer.Inner.Inner2 p1d) {}
// m2a-b both have the same parameter type.
void m2a(@A Inner.Inner2 p2a) {}
void m2b(Outer.@A Inner.Inner2 p2b) {}
// The location for @A is the same in m3a-c
void m3a(@A Outer p3a) {}
void m3b(@A Outer.Inner p3b) {}
void m3c(@A Outer.Inner.Inner2 p3c) {}
// Test combinations
void m4a(@A Outer p3a) {}
void m4b(@A Outer. @B Inner p3b) {}
void m4c(@A Outer. @B Inner. @C Inner2 p3c) {}
}
}
void m4a(@A Map p4a) {}
void m4b(Map.@B Entry p4c) {}
// Illegal:
// void m4b(@A Map.Entry p4b) {}
// void m4c(@A Map.@B Entry p4c) {}
void m4c(Map<String,String>.@B Entry p4d) {}
// Illegal:
// void m4d(@A Map<String,String>.@B Entry p4d) {}
void m4e(MyList<Map.Entry> p4e) {}
void m4f(MyList<Map.@B Entry> p4f) {}
// Illegal:
// void m4g(MyList<@A Map.Entry> p4e) {}
// void m4h(MyList<@A Map.@B Entry> p4f) {}
class GInner<X> {
class GInner2<Y, Z> {}
}
static class Static {}
static class GStatic<X, Y> {
static class GStatic2<Z> {}
}
}
class Test1 {
// Outer.GStatic<Object,Object>.GStatic2