Implementing class for ParameterizedType interface.
| Method from sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl Detail: |
public boolean equals(Object o) {
if (o instanceof ParameterizedType) {
// Check that information is equivalent
ParameterizedType that = (ParameterizedType) o;
if (this == that)
return true;
Type thatOwner = that.getOwnerType();
Type thatRawType = that.getRawType();
if (false) { // Debugging
boolean ownerEquality = (ownerType == null ?
thatOwner == null :
ownerType.equals(thatOwner));
boolean rawEquality = (rawType == null ?
thatRawType == null :
rawType.equals(thatRawType));
boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone
that.getActualTypeArguments());
for (Type t : actualTypeArguments) {
System.out.printf("\t\t%s%s%n", t, t.getClass());
}
System.out.printf("\towner %s\traw %s\ttypeArg %s%n",
ownerEquality, rawEquality, typeArgEquality);
return ownerEquality && rawEquality && typeArgEquality;
}
return
(ownerType == null ?
thatOwner == null :
ownerType.equals(thatOwner)) &&
(rawType == null ?
thatRawType == null :
rawType.equals(thatRawType)) &&
Arrays.equals(actualTypeArguments, // avoid clone
that.getActualTypeArguments());
} else
return false;
}
|
public Type[] getActualTypeArguments() {
return actualTypeArguments.clone();
}
Returns an array of Type objects representing the actual type
arguments to this type.
Note that in some cases, the returned array be empty. This can occur
if this type represents a non-parameterized type nested within
a parameterized type. |
public Type getOwnerType() {
return ownerType;
}
Returns a Type object representing the type that this type
is a member of. For example, if this type is O.I,
return a representation of O.
If this type is a top-level type, null is returned. |
public Class getRawType() {
return rawType;
}
Returns the Type object representing the class or interface
that declared this type. |
public int hashCode() {
return
Arrays.hashCode(actualTypeArguments) ^
(ownerType == null ? 0 : ownerType.hashCode() ) ^
(rawType == null ? 0 : rawType.hashCode() );
}
|
public static ParameterizedTypeImpl make(Class rawType,
Type[] actualTypeArguments,
Type ownerType) {
return new ParameterizedTypeImpl(rawType, actualTypeArguments,
ownerType);
}
Static factory. Given a (generic) class, actual type arguments
and an owner type, creates a parameterized type.
This class can be instantiated with a a raw type that does not
represent a generic type, provided the list of actual type
arguments is empty.
If the ownerType argument is null, the declaring class of the
raw type is used as the owner type.
This method throws a MalformedParameterizedTypeException
under the following circumstances:
If the number of actual type arguments (i.e., the size of the
array typeArgs) does not correspond to the number of
formal type arguments.
If any of the actual type arguments is not an instance of the
bounds on the corresponding formal. |
public String toString() {
StringBuilder sb = new StringBuilder();
if (ownerType != null) {
if (ownerType instanceof Class)
sb.append(((Class)ownerType).getName());
else
sb.append(ownerType.toString());
sb.append(".");
if (ownerType instanceof ParameterizedTypeImpl) {
// Find simple name of nested type by removing the
// shared prefix with owner.
sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$",
""));
} else
sb.append(rawType.getName());
} else
sb.append(rawType.getName());
if (actualTypeArguments != null &&
actualTypeArguments.length > 0) {
sb.append("< ");
boolean first = true;
for(Type t: actualTypeArguments) {
if (!first)
sb.append(", ");
if (t instanceof Class)
sb.append(((Class)t).getName());
else
sb.append(t.toString());
first = false;
}
sb.append(" >");
}
return sb.toString();
}
|