java.lang.Class.getDeclaredClasses()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(261)

本文整理了Java中java.lang.Class.getDeclaredClasses()方法的一些代码示例,展示了Class.getDeclaredClasses()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getDeclaredClasses()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getDeclaredClasses

Class.getDeclaredClasses介绍

[英]Returns an array containing Class objects for all classes and interfaces that are declared as members of the class which this Class represents. If there are no classes or interfaces declared or if this class represents an array class, a primitive type or void, then an empty array is returned.
[中]返回一个数组,该数组包含声明为该类所表示的类的成员的所有类和接口的类对象。如果没有声明类或接口,或者该类表示数组类、基元类型或void,则返回空数组。

代码示例

代码示例来源:origin: spring-projects/spring-loaded

public static Class[] callGetDeclaredClasses(Class thiz)
throws SecurityException
{
  return thiz.getDeclaredClasses();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public String[] getMemberClassNames() {
  LinkedHashSet<String> memberClassNames = new LinkedHashSet<>(4);
  for (Class<?> nestedClass : this.introspectedClass.getDeclaredClasses()) {
    memberClassNames.add(nestedClass.getName());
  }
  return StringUtils.toStringArray(memberClassNames);
}

代码示例来源:origin: neo4j/neo4j

public static Collection<Status> all()
{
  Collection<Status> result = new ArrayList<>();
  for ( Class<?> child : Status.class.getDeclaredClasses() )
  {
    if ( child.isEnum() && Status.class.isAssignableFrom( child ) )
    {
      @SuppressWarnings( "unchecked" )
      Class<? extends Status> statusType = (Class<? extends Status>) child;
      Collections.addAll( result, statusType.getEnumConstants() );
    }
  }
  return result;
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public TypeList getDeclaredTypes() {
  return new TypeList.ForLoadedTypes(type.getDeclaredClasses());
}

代码示例来源:origin: google/error-prone

/** Reflectively instantiate the package-private {@code MethodResolutionPhase} enum. */
private static Object newMethodResolutionPhase(boolean autoboxing) {
 for (Class<?> c : Resolve.class.getDeclaredClasses()) {
  if (!c.getName().equals("com.sun.tools.javac.comp.Resolve$MethodResolutionPhase")) {
   continue;
  }
  for (Object e : c.getEnumConstants()) {
   if (e.toString().equals(autoboxing ? "BOX" : "BASIC")) {
    return e;
   }
  }
 }
 return null;
}

代码示例来源:origin: org.springframework/spring-core

@Override
public String[] getMemberClassNames() {
  LinkedHashSet<String> memberClassNames = new LinkedHashSet<>(4);
  for (Class<?> nestedClass : this.introspectedClass.getDeclaredClasses()) {
    memberClassNames.add(nestedClass.getName());
  }
  return StringUtils.toStringArray(memberClassNames);
}

代码示例来源:origin: spring-projects/spring-framework

for (Class<?> candidate : declaringClass.getDeclaredClasses()) {
  if (isDefaultConfigurationClassCandidate(candidate)) {
    configClasses.add(candidate);

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

@NotNull
 private static Type getResultType(@NotNull String method) {
  for (Class<?> c : DlvRequest.class.getDeclaredClasses()) {
   if (method.equals(c.getSimpleName())) {
    Type s = c.getGenericSuperclass();
    assert s instanceof ParameterizedType : c.getCanonicalName() + " should have a generic parameter for correct callback processing";
    Type[] arguments = ((ParameterizedType)s).getActualTypeArguments();
    assert arguments.length == 1 : c.getCanonicalName() + " should have only one generic argument for correct callback processing";
    return arguments[0];
   }
  }
  CommandProcessorKt.getLOG().error("Unknown response " + method + ", please register an appropriate request into com.goide.dlv.protocol.DlvRequest");
  return Object.class;
 }
}

代码示例来源:origin: google/guava

public void testFinalizeClassHasNoNestedClasses() throws Exception {
  // Ensure that the Finalizer class has no nested classes.
  // See https://code.google.com/p/guava-libraries/issues/detail?id=1505
  assertEquals(Collections.emptyList(), Arrays.asList(Finalizer.class.getDeclaredClasses()));
 }
}

代码示例来源:origin: spring-projects/spring-framework

Class<?> sourceClass = (Class<?>) sourceToProcess;
try {
  Class<?>[] declaredClasses = sourceClass.getDeclaredClasses();
  List<SourceClass> members = new ArrayList<>(declaredClasses.length);
  for (Class<?> declaredClass : declaredClasses) {

代码示例来源:origin: apache/ignite

/**
 * Get inner class by its name from the enclosing class.
 *
 * @param parentCls Parent class to resolve inner class for.
 * @param innerClsName Name of the inner class.
 * @return Inner class.
 */
@Nullable public static <T> Class<T> getInnerClass(Class<?> parentCls, String innerClsName) {
  for (Class<?> cls : parentCls.getDeclaredClasses())
    if (innerClsName.equals(cls.getSimpleName()))
      return (Class<T>)cls;
  return null;
}

代码示例来源:origin: neo4j/neo4j

@BeforeClass
public static void collectAllDifferentInconsistencyTypes()
{
  Class<?> reportClass = ConsistencyReport.class;
  for ( Class<?> cls : reportClass.getDeclaredClasses() )
  {
    for ( Method method : cls.getDeclaredMethods() )
    {
      if ( method.getAnnotation( Documented.class ) != null )
      {
        Set<String> types = allReports.computeIfAbsent( cls, k -> new HashSet<>() );
        types.add( method.getName() );
      }
    }
  }
}

代码示例来源:origin: apache/hive

private final static void setEnv(Map<String, String> newenv) throws Exception {
 Class[] classes = Collections.class.getDeclaredClasses();
 Map<String, String> env = System.getenv();
 for (Class cl : classes) {
  if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
   Field field = cl.getDeclaredField("m");
   field.setAccessible(true);
   Object obj = field.get(env);
   Map<String, String> map = (Map<String, String>) obj;
   map.clear();
   map.putAll(newenv);
  }
 }
}

代码示例来源:origin: apache/hive

private final static void setEnv(Map<String, String> newenv) throws Exception {
 Class[] classes = Collections.class.getDeclaredClasses();
 Map<String, String> env = System.getenv();
 for (Class cl : classes) {
  if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
   Field field = cl.getDeclaredField("m");
   field.setAccessible(true);
   Object obj = field.get(env);
   Map<String, String> map = (Map<String, String>) obj;
   map.clear();
   map.putAll(newenv);
  }
 }
}

代码示例来源:origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
public static Map<String, String> getModifiableSystemEnvironment() {
  Class<?>[] classes = Collections.class.getDeclaredClasses();
  Map<String, String> env = System.getenv();
  for (Class<?> cl : classes) {

代码示例来源:origin: google/guava

public static <E extends Enum<?> & Feature<?>> void assertGoodFeatureEnum(
  Class<E> featureEnumClass) {
 final Class<?>[] classes = featureEnumClass.getDeclaredClasses();
 for (Class<?> containedClass : classes) {
  if (containedClass.getSimpleName().equals("Require")) {
   if (containedClass.isAnnotation()) {
    assertGoodTesterAnnotation(asAnnotation(containedClass));
   } else {
    fail(
      rootLocaleFormat(
        "Feature enum %s contains a class named "
          + "'Require' but it is not an annotation.",
        featureEnumClass));
   }
   return;
  }
 }
 fail(
   rootLocaleFormat(
     "Feature enum %s should contain an " + "annotation named 'Require'.",
     featureEnumClass));
}

代码示例来源:origin: udacity/ud851-Exercises

@Test
public void inner_class_exists() throws Exception {
  Class[] innerClasses = WaitlistContract.class.getDeclaredClasses();
  assertEquals("There should be 1 Inner class inside the contract class", 1, innerClasses.length);
}

代码示例来源:origin: udacity/ud851-Exercises

@Test
public void inner_class_type_correct() throws Exception {
  Class[] innerClasses = WaitlistContract.class.getDeclaredClasses();
  assertEquals("Cannot find inner class to complete unit test", 1, innerClasses.length);
  Class entryClass = innerClasses[0];
  assertTrue("Inner class should implement the BaseColumns interface", BaseColumns.class.isAssignableFrom(entryClass));
  assertTrue("Inner class should be final", Modifier.isFinal(entryClass.getModifiers()));
  assertTrue("Inner class should be static", Modifier.isStatic(entryClass.getModifiers()));
}

代码示例来源:origin: udacity/ud851-Exercises

@Test
public void inner_class_type_correct() throws Exception {
  Class[] innerClasses = WaitlistContract.class.getDeclaredClasses();
  assertEquals("Cannot find inner class to complete unit test", 1, innerClasses.length);
  Class entryClass = innerClasses[0];
  assertTrue("Inner class should implement the BaseColumns interface", BaseColumns.class.isAssignableFrom(entryClass));
  assertTrue("Inner class should be final", Modifier.isFinal(entryClass.getModifiers()));
  assertTrue("Inner class should be static", Modifier.isStatic(entryClass.getModifiers()));
}

代码示例来源:origin: udacity/ud851-Exercises

@Test
public void inner_class_type_correct() throws Exception {
  Class[] innerClasses = WaitlistContract.class.getDeclaredClasses();
  assertEquals("Cannot find inner class to complete unit test", 1, innerClasses.length);
  Class entryClass = innerClasses[0];
  assertTrue("Inner class should implement the BaseColumns interface", BaseColumns.class.isAssignableFrom(entryClass));
  assertTrue("Inner class should be final", Modifier.isFinal(entryClass.getModifiers()));
  assertTrue("Inner class should be static", Modifier.isStatic(entryClass.getModifiers()));
}

相关文章

微信公众号

最新文章

更多

Class类方法