1 package sun.reflect.generics.reflectiveObjects;
3 import java.lang.reflect.GenericArrayType;
4 import java.lang.reflect.Type;
5 import java.util.Objects;
8 * MJI model class for sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
10 * This is a JPF specific version of a system class because we can't use the real,
11 * platform VM specific version (it's native all over the place, its field
12 * structure isn't documented, most of its methods are private, hence we can't
13 * even instantiate it properly).
15 * Note that this class never gets seen by the real VM - it's for JPF's eyes only.
17 * For now this only supports a few basic methods.
19 public class GenericArrayTypeImpl
20 implements GenericArrayType {
21 private final Type genericComponentType;
23 // private constructor enforces use of static factory
24 private GenericArrayTypeImpl(Type ct) {
25 genericComponentType = ct;
30 * @param ct - the desired component type of the generic array type
32 * @return a generic array type with the desired component type
34 public static GenericArrayTypeImpl make(Type ct) {
35 return new GenericArrayTypeImpl(ct);
40 * Returns a <tt>Type</tt> object representing the component type
43 * @return a <tt>Type</tt> object representing the component type
47 public Type getGenericComponentType() {
48 return genericComponentType; // return cached component type
51 public String toString() {
52 Type componentType = getGenericComponentType();
53 StringBuilder sb = new StringBuilder();
55 if (componentType instanceof Class)
56 sb.append(((Class)componentType).getName() );
58 sb.append(componentType.toString());
64 public boolean equals(Object o) {
65 if (o instanceof GenericArrayType) {
66 GenericArrayType that = (GenericArrayType) o;
68 return Objects.equals(genericComponentType, that.getGenericComponentType());
74 public int hashCode() {
75 return Objects.hashCode(genericComponentType);