Methods Summary |
---|
private native T | constructNative(java.lang.Object[] args, java.lang.Class declaringClass, java.lang.Class[] parameterTypes, int slot, boolean noAccessCheck)
|
public boolean | equals(java.lang.Object object)Indicates whether or not the specified {@code object} is equal to this
constructor. To be equal, the specified object must be an instance
of {@code Constructor} with the same declaring class and parameter types
as this constructor.
return object instanceof Constructor && toString().equals(object.toString());
|
private native int | getConstructorModifiers(java.lang.Class declaringClass, int slot)
|
public java.lang.annotation.Annotation[] | getDeclaredAnnotations()
return getDeclaredAnnotations(declaringClass, slot);
|
private native java.lang.annotation.Annotation[] | getDeclaredAnnotations(java.lang.Class declaringClass, int slot)
|
public java.lang.Class | getDeclaringClass()Returns the class that declares this constructor.
return declaringClass;
|
public java.lang.Class[] | getExceptionTypes()Returns the exception types as an array of {@code Class} instances. If
this constructor has no declared exceptions, an empty array will be
returned.
if (exceptionTypes == null)
return new Class[0];
return exceptionTypes;
|
public java.lang.reflect.Type[] | getGenericExceptionTypes()Returns the exception types as an array of {@code Type} instances. If
this constructor has no declared exceptions, an empty array will be
returned.
initGenericTypes();
return Types.getClonedTypeArray(genericExceptionTypes);
|
public java.lang.reflect.Type[] | getGenericParameterTypes()Returns the generic parameter types as an array of {@code Type}
instances, in declaration order. If this constructor has no generic
parameters, an empty array is returned.
initGenericTypes();
return Types.getClonedTypeArray(genericParameterTypes);
|
public int | getModifiers()Returns the modifiers for this constructor. The {@link Modifier} class
should be used to decode the result.
return getConstructorModifiers(declaringClass, slot);
|
public java.lang.String | getName()Returns the name of this constructor.
return declaringClass.getName();
|
public java.lang.annotation.Annotation[][] | getParameterAnnotations()Returns an array of arrays that represent the annotations of the formal
parameters of this constructor. If there are no parameters on this
constructor, then an empty array is returned. If there are no annotations
set, then an array of empty arrays is returned.
Annotation[][] parameterAnnotations
= getParameterAnnotations(declaringClass, slot);
if (parameterAnnotations.length == 0) {
return Method.noAnnotations(parameterTypes.length);
}
return parameterAnnotations;
|
private native java.lang.annotation.Annotation[][] | getParameterAnnotations(java.lang.Class declaringClass, int slot)
|
public java.lang.Class[] | getParameterTypes()Returns an array of the {@code Class} objects associated with the
parameter types of this constructor. If the constructor was declared with
no parameters, an empty array will be returned.
return parameterTypes;
|
private java.lang.String | getSignature()Returns the constructor's signature in non-printable form. This is called
(only) from IO native code and needed for deriving the serialVersionUID
of the class
StringBuilder result = new StringBuilder();
result.append('(");
for(int i = 0; i < parameterTypes.length; i++) {
result.append(getSignature(parameterTypes[i]));
}
result.append(")V");
return result.toString();
|
private native java.lang.Object[] | getSignatureAnnotation(java.lang.Class declaringClass, int slot)Get the Signature annotation for this constructor. Returns null if not
found.
|
java.lang.String | getSignatureAttribute()
Object[] annotation = getSignatureAnnotation(declaringClass, slot);
if (annotation == null) {
return null;
}
return StringUtils.combineStrings(annotation);
|
public java.lang.reflect.TypeVariable[] | getTypeParameters()
initGenericTypes();
return formalTypeParameters.clone();
|
public int | hashCode()Returns an integer hash code for this constructor. Constructors which are
equal return the same value for this method. The hash code for a
Constructor is the hash code of the name of the declaring class.
return declaringClass.getName().hashCode();
|
private synchronized void | initGenericTypes()
if (!genericTypesAreInitialized) {
String signatureAttribute = getSignatureAttribute();
GenericSignatureParser parser = new GenericSignatureParser(
VMStack.getCallingClassLoader2());
parser.parseForConstructor(this, signatureAttribute);
formalTypeParameters = parser.formalTypeParameters;
genericParameterTypes = parser.parameterTypes;
genericExceptionTypes = parser.exceptionTypes;
genericTypesAreInitialized = true;
}
|
public boolean | isSynthetic()Indicates whether or not this constructor is synthetic (artificially
introduced by the compiler).
int mods = getConstructorModifiers(declaringClass, slot);
return (mods & Modifier.SYNTHETIC) != 0;
|
public boolean | isVarArgs()Indicates whether or not this constructor takes a variable number of
arguments.
int mods = getConstructorModifiers(declaringClass, slot);
return (mods & Modifier.VARARGS) != 0;
|
public T | newInstance(java.lang.Object args)Returns a new instance of the declaring class, initialized by dynamically
invoking the constructor represented by this {@code Constructor} object.
This reproduces the effect of {@code new declaringClass(arg1, arg2, ... ,
argN)} This method performs the following:
- A new instance of the declaring class is created. If the declaring
class cannot be instantiated (i.e. abstract class, an interface, an array
type, or a primitive type) then an InstantiationException is thrown.
- If this Constructor object is enforcing access control (see
{@link AccessibleObject}) and this constructor is not accessible from the
current context, an IllegalAccessException is thrown.
- If the number of arguments passed and the number of parameters do not
match, an IllegalArgumentException is thrown.
- For each argument passed:
- If the corresponding parameter type is a primitive type, the argument
is unwrapped. If the unwrapping fails, an IllegalArgumentException is
thrown.
- If the resulting argument cannot be converted to the parameter type
via a widening conversion, an IllegalArgumentException is thrown.
- The constructor represented by this {@code Constructor} object is
then invoked. If an exception is thrown during the invocation, it is
caught and wrapped in an InvocationTargetException. This exception is
then thrown. If the invocation completes normally, the newly initialized
object is returned.
return constructNative (args, declaringClass, parameterTypes, slot, flag);
|
public java.lang.String | toGenericString()Returns the string representation of the constructor's declaration,
including the type parameters.
StringBuilder sb = new StringBuilder(80);
initGenericTypes();
// append modifiers if any
int modifier = getModifiers();
if (modifier != 0) {
sb.append(Modifier.toString(modifier & ~Modifier.VARARGS)).append(' ");
}
// append type parameters
if (formalTypeParameters != null && formalTypeParameters.length > 0) {
sb.append('<");
for (int i = 0; i < formalTypeParameters.length; i++) {
appendGenericType(sb, formalTypeParameters[i]);
if (i < formalTypeParameters.length - 1) {
sb.append(", ");
}
}
sb.append("> ");
}
// append constructor name
appendArrayType(sb, getDeclaringClass());
// append parameters
sb.append('(");
appendArrayGenericType(sb,
Types.getClonedTypeArray(genericParameterTypes));
sb.append(')");
// append exeptions if any
Type[] genericEceptionTypeArray =
Types.getClonedTypeArray(genericExceptionTypes);
if (genericEceptionTypeArray.length > 0) {
sb.append(" throws ");
appendArrayGenericType(sb, genericEceptionTypeArray);
}
return sb.toString();
|
public java.lang.String | toString()Returns a string containing a concise, human-readable description of this
constructor. The format of the string is:
- modifiers (if any)
- declaring class name
- '('
- parameter types, separated by ',' (if any)
- ')'
- 'throws' plus exception types, separated by ',' (if any)
For example:
{@code public String(byte[],String) throws UnsupportedEncodingException}
StringBuilder result = new StringBuilder(Modifier.toString(getModifiers()));
if (result.length() != 0)
result.append(' ");
result.append(declaringClass.getName());
result.append("(");
result.append(toString(parameterTypes));
result.append(")");
if (exceptionTypes != null && exceptionTypes.length != 0) {
result.append(" throws ");
result.append(toString(exceptionTypes));
}
return result.toString();
|