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

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

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

Class.getClasses介绍

[英]Returns an array containing Class objects for all public classes and interfaces that are members of this class. This includes public members inherited from super classes and interfaces. If there are no such class members or if this object represents a primitive type then an array of length 0 is returned.
[中]返回一个数组,该数组包含作为此类成员的所有公共类和接口的类对象。这包括从超类和接口继承的公共成员。如果没有此类类成员,或者如果此对象表示基元类型,则返回长度为0的数组。

代码示例

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

/**
   * Only called reflectively. Do not use programmatically.
   */
  public Enclosed(Class<?> klass, RunnerBuilder builder) throws Throwable {
    super(builder, klass, klass.getClasses());
  }
}

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

public static Class[] callGetClasses(Class thiz)
{
  return thiz.getClasses();
}

代码示例来源:origin: junit-team/junit4

/**
 * Only called reflectively. Do not use programmatically.
 */
public Enclosed(Class<?> klass, RunnerBuilder builder) throws Throwable {
  super(builder, klass, filterAbstractClasses(klass.getClasses()));
}

代码示例来源:origin: org.testng/testng

private void registerClass(Class<?> cl, XmlClass xmlClass) {
 m_map.put(cl, xmlClass);
 if (includeNestedClasses) {
  for (Class<?> c : cl.getClasses()) {
   if (!m_map.containsKey(c)) {
    registerClass(c, xmlClass);
   }
  }
 }
}

代码示例来源:origin: stackoverflow.com

Class serviceManagerClass = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClass.getMethod("getService", String.class);
IBinder retbinder = (IBinder) getService.invoke(serviceManagerClass, "statusbar");
Class statusBarClass = Class.forName(retbinder.getInterfaceDescriptor());
Object statusBarObject = statusBarClass.getClasses()[0].getMethod("asInterface", IBinder.class).invoke(null, new Object[] { retbinder });
Method clearAll = statusBarClass.getMethod("toggleRecentApps");
clearAll.setAccessible(true);
clearAll.invoke(statusBarObject);

代码示例来源:origin: cbeust/testng

private void registerClass(Class<?> cl, XmlClass xmlClass) {
 m_map.put(cl, xmlClass);
 if (includeNestedClasses) {
  for (Class<?> c : cl.getClasses()) {
   if (!m_map.containsKey(c)) {
    registerClass(c, xmlClass);
   }
  }
 }
}

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

private void addRClassValues(PackageResourceTable resourceTable, Class<?> rClass) {
 for (Class innerClass : rClass.getClasses()) {
  String resourceType = innerClass.getSimpleName();
  if (!resourceType.equals("styleable")) {
   for (Field field : innerClass.getDeclaredFields()) {
    if (field.getType().equals(Integer.TYPE) && Modifier.isStatic(field.getModifiers())) {
     int id;
     try {
      id = field.getInt(null);
     } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
     }
     String resourceName = field.getName();
     resourceTable.addResource(id, resourceType, resourceName);
    }
   }
  }
 }
}

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

public TeXIconBuilder(String tex, Color foregroundColor) throws ClassNotFoundException, NoSuchMethodException,
    SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException,
    InvocationTargetException {
  // TeXFormula formula = new TeXFormula(latex);
  final Class<?> clTeXFormula = Class.forName("org.scilab.forge.jlatexmath.TeXFormula");
  final Object formula = clTeXFormula.getConstructor(String.class).newInstance(tex);
  // TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(20).build();
  final Class<?> clTeXIconBuilder = clTeXFormula.getClasses()[0];
  final Object builder = clTeXIconBuilder.getConstructors()[0].newInstance(formula);
  clTeXIconBuilder.getMethod("setStyle", int.class).invoke(builder, 0);
  clTeXIconBuilder.getMethod("setSize", float.class).invoke(builder, (float) 20);
  icon = (Icon) clTeXIconBuilder.getMethod("build").invoke(builder);
  final int margin = 1;
  final Insets insets = new Insets(margin, margin, margin, margin);
  icon.getClass().getMethod("setInsets", insets.getClass()).invoke(icon, insets);
  icon.getClass().getMethod("setForeground", foregroundColor.getClass()).invoke(icon, foregroundColor);
}

代码示例来源:origin: stackoverflow.com

r = Class.forName(packageName + ".R");
Class[] classes = r.getClasses();
Class desireClass = null;

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

for (Class innerClass : rClass.getClasses()) {
 if (innerClass.getSimpleName().equals("styleable")) {

代码示例来源:origin: stackoverflow.com

Object serviceManagerObject;
telephonyClass = Class.forName(telephonyName);
telephonyStubClass = telephonyClass.getClasses()[0];
serviceManagerClass = Class.forName(serviceManagerName);
serviceManagerNativeClass = Class.forName(serviceManagerNativeName);

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

@Test
  public void iteration() throws SecurityException, NoSuchMethodException {
    List<Class<?>> types = new ArrayList<Class<?>>();
//        types.addAll(Arrays.<Class<?>>asList(Alias.class.getClasses()));
    types.addAll(Arrays.asList(Operation.class.getClasses()));
    types.addAll(Arrays.asList(Path.class.getClasses()));
    for (Class<?> innerType : types) {
      if (!innerType.isInterface() && Expression.class.isAssignableFrom(innerType)) {
        Visitor.class.getDeclaredMethod("visit",innerType);
      }
    }
    System.out.println("successful for " + types.size() + " types");
  }

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

private Optional<Method> getImplementation(Class<?> type, Method method) {
    return Stream.of(type.getClasses())
        .filter(c -> c.getSimpleName().equals("DefaultImpls"))
        .flatMap(c -> Stream.of(c.getMethods()).filter(m -> m.getName().equals(method.getName())))
        .findAny();
  }
};

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

for ( Class<?> cmd : Command.class.getClasses() )
for ( Class<?> cmd : IndexCommand.class.getClasses() )

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

@Test
public void testExpr() {
  for (Class<?> cl : Expression.class.getClasses()) {
    assertTrue(cl.getName(), Expression.class.isAssignableFrom(cl));
  }
}

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

@Test
public void testPath() {
  for (Class<?> cl : Path.class.getClasses()) {
    assertTrue(cl.getName(), Path.class.isAssignableFrom(cl));
    if (!cl.isInterface()) {
      assertTrue(cl.getName(), Expression.class.isAssignableFrom(cl));
    }
  }
}

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

@Test
public void test() {
  GenericExporter exporter = new GenericExporter();
  exporter.setTargetFolder(new File("target/" + getClass().getSimpleName()));
  exporter.export(getClass().getClasses());
}

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

@Test
public void test() {
  GenericExporter exporter = new GenericExporter();
  exporter.setTargetFolder(new File("target/" + getClass().getSimpleName()));
  exporter.export(getClass().getClasses());
}

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

@SuppressWarnings("unchecked")
@Test
public void patternAvailability() throws IllegalArgumentException, IllegalAccessException {
  Templates ops = new DummyTemplates();
  Set<Field> missing = new HashSet<Field>();
  for (Field field : Ops.class.getFields()) {
    if (field.getType().equals(Operator.class)) {
      Operator op = (Operator) field.get(null);
      if (ops.getTemplate(op) == null) {
        missing.add(field);
      }
    }
  }
  for (Class<?> cl : Ops.class.getClasses()) {
    for (Field field : cl.getFields()) {
      if (field.getType().equals(Operator.class)) {
        Operator op = (Operator) field.get(null);
        if (ops.getTemplate(op) == null) {
          missing.add(field);
        }
      }
    }
  }
  if (!missing.isEmpty()) {
    for (Field field : missing) {
      System.err.println(field.getName());
    }
    fail();
  }
}

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

@Test
  public void export() {
    GenericExporter exporter = new GenericExporter();
    exporter.setTargetFolder(new File("target/Generic2Test"));
    exporter.export(Generic2Test.class.getClasses());
  }
}

相关文章

Class类方法