Class getSigners() method in Java with Examples

The getSigners() method of java.lang.Class class is used to get the signers of this class. The method returns the signers of this class. If this object represents a primitive type or void, then this method returns null.
Â
Syntax:Â Â
public Object[] getSigners()
Parameter: This method does not accept any parameter.
Return Value: This method returns the signers of this class. If this object represents a primitive type or void, then this method returns null.
Below programs demonstrate the getSigners() method.
Example 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()));    }} |
Output:Â
Class represented by myClass: class Test Signers of myClass: null
Â
Example 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()));    }} |
Output:Â
Signers of myClass: null
Â
Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#getSigners–Â



