类的类getClasses()方法 (Class class getClasses() method)
getClasses() method is available in java.lang package.
getClasses()方法在java.lang包中可用。
getClasses() method is used to return an array that contains Class objects denoting all the public classes and interfaces that are a member of the class denoted by this Class object and it includes public class and interface members inherited from parent classes.
getClasses()方法用于返回一个数组,该数组包含表示所有公共类和接口的Class对象,这些公共类和接口是此Class对象所表示的类的成员,并且包括从父类继承的公共类和接口成员。
getClasses() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
getClasses()方法是一个非静态方法,只能通过类对象进行访问,如果尝试使用类名访问该方法,则会收到错误消息。
getClasses() method may throw SecurityException at the time of checking security constraints.SecurityException: This exception raise when security manager exists.
在检查安全性约束时, getClasses()方法可能会引发SecurityException。SecurityException:当安全管理器存在时引发此异常。
Syntax:
句法:
public Class[] getClasses();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is Class[], it returns an array of Class objects denoting the public members of this class.
此方法的返回类型为Class [] ,它返回表示该类的公共成员的Class对象的数组。
Example:
例:
// Java program to demonstrate the example
// of Class[] getClasses() method of Class
public class GetClassesOfClass {
public static void main(String[] args) throws Exception {
// It returns the Class object attached
// with the given classname
Class cl = Class.forName("java.lang.ClassLoader");
// It returns an array of Class objects denotes the public
// member of the class "java.lang.ClassLoader"
Class[] public_classes = cl.getClasses();
// Traversing ClassLoader class
for (int i = 1; i <= public_classes.length; ++i) {
System.out.print("Class Name: ");
System.out.println(public_classes[i].getName());
}
}
}
Output
输出量
翻译自: https://www.includehelp.com/java/class-class-getclasses-method-with-example.aspx