java.lang.Object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.lang.reflect.AccessibleObject | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.lang.reflect.Constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constructor provides information about a single constructor for a class.
Get the annotation declared for this constructor
Return | Method | Summary |
---|---|---|
<T extends Annotation>T | getAnnotation(Class<T> annotationClass) | Returns this element's annotation for the specified type if such an annotation is present, else null. |
Annotation[] | getDeclaredAnnotations() | Returns all annotations that are directly present on this element. |
Get the declaring class
Return | Method | Summary |
---|---|---|
Class<T> | getDeclaringClass() | Returns the Class object representing the class that declares the constructor represented by this Constructor object. |
Get the generic exception types
Return | Method | Summary |
---|---|---|
Class<?>[] | getExceptionTypes() | Returns an array of Class objects that represent the types of exceptions declared to be thrown by the underlying constructor represented by this Constructor object. |
Type[] | getGenericExceptionTypes() | Returns an array of Type objects that represent the exceptions declared to be thrown by this Constructor object. |
Get the generic parameter types
Return | Method | Summary |
---|---|---|
Type[] | getGenericParameterTypes() | Returns an array of Type objects that represent the formal parameter types, in declaration order, of the method represented by this Constructor object. |
Get the modifiers
Return | Method | Summary |
---|---|---|
int | getModifiers() | Returns the Java language modifiers for the constructor represented by this Constructor object, as an integer. |
Get the name of the contructor
Return | Method | Summary |
---|---|---|
String | getName() | Returns the name of this constructor, as a string. |
Get parameter's annotation, type
Return | Method | Summary |
---|---|---|
Annotation[][] | getParameterAnnotations() | Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Constructor object. |
Class<?>[] | getParameterTypes() | Returns an array of Class objects that represent the formal parameter types, in declaration order, of the constructor represented by this Constructor object. |
Get typed parameters
Return | Method | Summary |
---|---|---|
TypeVariable<Constructor<T>>[] | getTypeParameters() | Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order. |
Is this contructor a Synthetic, and does it have the variable number of arguments
Return | Method | Summary |
---|---|---|
boolean | isSynthetic() | Returns true if this constructor is a synthetic constructor; returns false otherwise. |
boolean | isVarArgs() | Returns true if this constructor was declared to take a variable number of arguments; returns false otherwise. |
Create new instance using the Contructor
Return | Method | Summary |
---|---|---|
T | newInstance(Object... initargs) | Uses the constructor represented by this Constructor object to create and initialize a new instance of the constructor's declaring class, with the specified initialization parameters. |
String representation of the contructor
Return | Method | Summary |
---|---|---|
String | toGenericString() | Returns a string describing this Constructor, including type parameters. |
String | toString() | Returns a string describing this Constructor. |
import java.lang.reflect.Constructor;
public class Main {
public static void main(String[] argv) throws Exception {
Constructor[] constructors = String.class.getDeclaredConstructors();
for (int i = 0; i < constructors.length; i++) {
Constructor c = constructors[i];
System.out.println(c.toGenericString());
}
}
}
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |