Java Class getSigners() 方法



描述

Java Class getSigners() 方法獲取此類的簽名者。

宣告

以下是java.lang.Class.getSigners() 方法的宣告

public Object[] getSigners()

引數

返回值

此方法返回此類的簽名者,如果沒有簽名者則返回 null,如果此物件表示基本型別或 void,則返回 null。

異常

獲取類簽名者示例

以下示例演示了 java.lang.Class.getSigners() 方法的使用。在這個程式中,使用 forName() 方法檢索 ClassDemo 的類。使用 getName(),我們檢索了類的名稱,然後使用 getSigner() 方法檢索簽名者並打印出來。

package com.tutorialspoint;

public class ClassDemo {

   public static void main(String[] args) {

      try {  
         Class cls = Class.forName("com.tutorialspoint.ClassDemo"); 

         // returns the name of the class
         System.out.println("Class = " + cls.getName());
        
         Object[] obj = cls.getSigners();
         System.out.println("Value = " + obj); 
      } catch(ClassNotFoundException ex) {
         System.out.println(ex.toString());
      }
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Class = com.tutorialspoint.ClassDemo
Value = null

獲取 ArrayList 簽名者示例

以下示例演示了 java.lang.Class.getSigners() 方法的使用。在這個程式中,我們使用了 ArrayList 的類,然後使用 getSigner() 方法檢索簽名者並打印出來。

package com.tutorialspoint;

import java.util.ArrayList;

public class ClassDemo {

   public static void main(String[] args) {

      Class cls = ArrayList.class; 

      // returns the name of the class
      System.out.println("Class = " + cls.getName());
        
      Object[] obj = cls.getSigners();
      System.out.println("Value = " + obj); 
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Class = java.util.ArrayList
Value = null

獲取 Thread 簽名者示例

以下示例演示了 java.lang.Class.getSigners() 方法的使用。在這個程式中,我們使用了 Thread 的類,然後使用 getSigner() 方法檢索簽名者並打印出來。

package com.tutorialspoint;

public class ClassDemo {

   public static void main(String[] args) {

      Class cls = Thread.class; 

      // returns the name of the class
      System.out.println("Class = " + cls.getName());
        
      Object[] obj = cls.getSigners();
      System.out.println("Value = " + obj); 
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Class = java.lang.Thread
Value = null
java_lang_class.htm
廣告