java.lang.reflect.Constructor.getParameterAnnotations()
方法返回一個陣列的陣列,它們表示由Constructor
物件表示的方法的形式引數(以宣告順序)的註釋。 (如果底層方法是無引數的,則返回一個長度為零的陣列,如果該方法具有一個或多個引數,則對於每個沒有註釋的引數,返回長度為零的巢狀陣列)。返回的陣列中包含的註釋物件是可序列化的。 該方法的呼叫者可以自由修改返回的陣列; 它將對返回給其他呼叫者的陣列沒有影響。
以下是java.lang.reflect.Constructor.getParameterAnnotations()
方法的宣告。
public Annotation[][] getParameterAnnotations()
返回值
以下範例顯示了java.lang.reflect.Constructor.getParameterAnnotations()
方法的用法。
import java.lang.reflect.Constructor;
public class GetName {
public static void main(String[] args) {
Constructor[] constructors = SampleClass.class.getDeclaredConstructors();
for (Constructor constructor : constructors) {
System.out.println("Constructor: " + constructor.getName());
}
}
}
class SampleClass {
private String sampleField;
public SampleClass() throws ArrayIndexOutOfBoundsException {
}
private SampleClass(String sampleField){
this.sampleField = sampleField;
}
public String getSampleField() {
return sampleField;
}
public void setSampleField(String sampleField) {
this.sampleField = sampleField;
}
}
讓我們編譯並執行上面的程式,這將產生以下結果 -
F:\worksp\javareflect>java GetParameterAnnotations
name: sampleClassConstructor
value: Sample Constructor Annotation