Java类class getClasses()方法及示例

类的类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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值