public enum NestingKind extends Enum<NestingKind>
请注意,未来版本的平台中可能会添加其他嵌套类型。
示例:下面的类使用它们的嵌套类型进行注释。
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
import javax.lang.model.element.*;
import static javax.lang.model.element.NestingKind.*;
@Nesting(TOP_LEVEL)
public class NestingExamples {
@Nesting(MEMBER)
static class MemberClass1{}
@Nesting(MEMBER)
class MemberClass2{}
public static void main(String... argv) {
@Nesting(LOCAL)
class LocalClass{};
Class<?>[] classes = {
NestingExamples.class,
MemberClass1.class,
MemberClass2.class,
LocalClass.class
};
for(Class<?> clazz : classes) {
System.out.format("%s is %s%n",
clazz.getName(),
clazz.getAnnotation(Nesting.class).value());
}
}
}
@Retention(RUNTIME)
@interface Nesting {
NestingKind value();
}
| Enum Constant and Description |
|---|
ANONYMOUS
没有名字的类型
|
LOCAL
在类型之外的构造中声明的命名类型。
|
MEMBER
作为另一种类型的命名成员的类型。
|
TOP_LEVEL
顶级类型,不包含在其他类型中。
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isNested()
这个常数是否对应于嵌套的类型元素?
嵌套类型元素是不是顶级的。
|
static NestingKind |
valueOf(String name)
以指定的名称返回此类型的枚举常量。
|
static NestingKind[] |
values()
按照它们声明的顺序返回一个包含此枚举类型常量的数组。
|
public static final NestingKind TOP_LEVEL
public static final NestingKind MEMBER
public static final NestingKind LOCAL
public static final NestingKind ANONYMOUS
public static NestingKind[] values()
for (NestingKind c : NestingKind.values())
System.out.println(c);
public static NestingKind valueOf(String name)
name - 要返回的枚举常量的名称。
IllegalArgumentException - 如果此枚举类型没有指定名称的常量
NullPointerException - 如果参数为null
public boolean isNested()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.