📜  Java中的类 getSigners() 方法和示例

📅  最后修改于: 2022-05-13 01:54:39.370000             🧑  作者: Mango

Java中的类 getSigners() 方法和示例

Java.lang.Class 类getSigners()方法用于获取该类的签名者。该方法返回此类的签名者。如果此对象表示原始类型或 void,则此方法返回 null。

句法:

public Object[] getSigners()

参数:此方法不接受任何参数。
返回值:此方法返回此类的签名者。如果此对象表示原始类型或 void,则此方法返回 null。
下面的程序演示了 getSigners() 方法。
示例 1:

Java
// Java program to demonstrate getSigners() method
 
import java.util.*;
 
public class Test {
    public static void main(String[] args)
        throws ClassNotFoundException
    {
 
        // returns the Class object for this class
        Class myClass = Class.forName("Test");
 
        System.out.println("Class represented by myClass: "
                           + myClass.toString());
 
        // Get the signers of myClass
        // using getSigners() method
        System.out.println(
            "Signers of myClass: "
            + Arrays.toString(
                  myClass.getSigners()));
    }
}


Java
// Java program to demonstrate getSigners() method
 
import java.util.*;
 
public class Test {
 
    public static void main(String[] args)
        throws ClassNotFoundException
    {
        // returns the Class object
        Class myClass = Class.forName("java.lang.Integer");
 
        // Get the signers of myClass
        // using getSigners() method
        System.out.println(
            "Signers of myClass: "
            + Arrays.toString(
                  myClass.getSigners()));
    }
}


输出:
Class represented by myClass: class Test
Signers of myClass: null

示例 2:

Java

// Java program to demonstrate getSigners() method
 
import java.util.*;
 
public class Test {
 
    public static void main(String[] args)
        throws ClassNotFoundException
    {
        // returns the Class object
        Class myClass = Class.forName("java.lang.Integer");
 
        // Get the signers of myClass
        // using getSigners() method
        System.out.println(
            "Signers of myClass: "
            + Arrays.toString(
                  myClass.getSigners()));
    }
}
输出:
Signers of myClass: null

参考: https://docs.oracle.com/javase/9/docs/api/ Java/lang/Class.html#getSigners–