JavaTM 2 Platform
Standard Ed. 6

javax.lang.model.element
枚举 NestingKind

java.lang.Object
  继承者 java.lang.Enum<NestingKind>
      继承者 javax.lang.model.element.NestingKind
所有已实现的接口:
Serializable, Comparable<NestingKind>

public enum NestingKind
extends Enum<NestingKind>

某一类型元素的嵌套种类 (nesting kind)。类型元素的种类有四种:top-level(顶层)、member(成员)、local(局部)和 anonymous(匿名)。嵌套种类 是一个非标准术语,在这里使用它是为了表示这种分类。

注意,在平台的未来版本中可能添加其他嵌套种类。

示例: 以下类是使用其嵌套种类注释的。


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();
 }
 

从以下版本开始:
1.6

枚举常量摘要
ANONYMOUS
           
LOCAL
           
MEMBER
           
TOP_LEVEL
           
 
方法摘要
 boolean isNested()
          此常量是否对应于嵌套类型元素?嵌套 (nested) 类型元素是任何非顶层的元素。
static NestingKind valueOf(String name)
          返回带有指定名称的该类型的枚举常量。
static NestingKind[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
从类 java.lang.Enum 继承的方法
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
从类 java.lang.Object 继承的方法
getClass, notify, notifyAll, wait, wait, wait
 

枚举常量详细信息

TOP_LEVEL

public static final NestingKind TOP_LEVEL

MEMBER

public static final NestingKind MEMBER

LOCAL

public static final NestingKind LOCAL

ANONYMOUS

public static final NestingKind ANONYMOUS
方法详细信息

values

public static final NestingKind[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for(NestingKind c : NestingKind.values())
        System.out.println(c);

返回:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static NestingKind valueOf(String name)
返回带有指定名称的该类型的枚举常量。 字符串必须与用于声明该类型的枚举常量的 标识符完全匹配。(不允许有多余 的空格。)

参数:
指定要返回的枚举常量的名称。 -
返回:
返回带有指定名称的枚举常量
抛出:
如果该枚举类型没有带有指定名称的常量, - 则抛出 IllegalArgumentException

isNested

public boolean isNested()
此常量是否对应于嵌套类型元素?嵌套 (nested) 类型元素是任何非顶层的元素。内部 (inner) 类型元素是任何非 static 的嵌套类型元素。


JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only