Note: The rules governing how it is - * determined whether any given configuration-related object is - * "of the supplied {@code type}" are currently wholly - * undefined.
- * - *Implementations of this method may or may not return a determinate - * value.
- * - * @paramTo use this class, create a new instance of an anonymous - * subclass of it, and then call {@link #type() type()} on it. For - * example:
- * - *- * - * @param- * // type will be a {@linkplain ParameterizedType} whose {@linkplain ParameterizedType#getRawType() rawType} is {@linkplain java.util.List List.class} and - * // whose {@linkplain ParameterizedType#getActualTypeArguments() sole type argument} is {@linkplain String String.class} - * {@linkplain Type} type = new {@linkplain TypeToken TypeToken}<{@linkplain java.util.List List}<{@linkplain String}>>() {}.{@linkplain #type() type()}; - * assert type instanceof {@linkplain ParameterizedType}; - * assert (({@linkplain ParameterizedType})type).{@linkplain ParameterizedType#getRawType() getRawType()} == {@linkplain java.util.List List.class}; - * assert (({@linkplain ParameterizedType})type).{@linkplain ParameterizedType#getActualTypeArguments() getActualTypeArguments()}[0] == {@linkplain String String.class};
This method never returns {@code null}.
- * - *This method produces a determinate - * value.
- * - *This method is idempotent.
- * - *This method is safe for concurrent use by multiple - * threads.
- * - * @return the {@link Type} modeled by this {@link TypeToken}; - * never {@code null} - */ - public final Type type() { - return this.type; - } - - /** - * Returns the {@linkplain #erase(Type) type erasure} of this {@link - * TypeToken}'s {@linkplain #type() modeledType
}, or
- * {@code null} if erasing the {@link Type} would result in a
- * non-{@link Class} erasure (in which case the erasure is simply
- * the {@link Type} itself), or if an erasure cannot be determined.
- *
- * This method never returns {@code null}.
- * - *This method produces a determinate - * value.
- * - *This method is idempotent.
- * - *This method is safe for concurrent use by multiple - * threads.
- * - * @return the {@linkplain #erase(Type) type erasure} of this {@link - * TypeToken}'s {@linkplain #type() modeledType
}, or
- * {@code null} if erasing the {@link Type} would result in a
- * non-{@link Class} erasure, or if an erasure cannot be determined
- */
- public final Class> erase() {
- return erase(this.type());
- }
-
- /**
- * Returns a hashcode for this {@link TypeToken} computed from the
- * {@link Type} it {@linkplain #type() models}.
- *
- * This method produces a determinate - * value.
- * - *This method is idempotent.
- * - *This method is safe for concurrent use by multiple - * threads.
- * - * @return a hashcode for this {@link TypeToken} - * - * @see #equals(Object) - */ - @Override // Object - public int hashCode() { - Type type = this.type(); - return type == null ? 0 : type.hashCode(); - } - - /** - * Returns {@code true} if the supplied {@link Object} is equal to - * this {@link TypeToken}. - * - *This method returns {@code true} if the supplied {@link
- * Object}'s {@linkplain Object#getClass() class} is this {@link
- * TypeToken}'s class and if its {@linkplain #type() modeled
- * Type
} is equal to this {@link TypeToken}'s
- * {@linkplain #type() modeled Type
}.
This method produces a determinate - * value.
- * - *This method is idempotent.
- * - *This method is safe for concurrent use by multiple - * threads.
- * - * @param other the {@link Object} to test; may be {@code null} in - * which case {@code false} will be returned - * - * @return {@code true} if the supplied {@link Object} is equal to - * this {@link TypeToken}; {@code false} otherwise - * - * @see #hashCode() - */ - @Override // Object - public boolean equals(Object other) { - if (other == this) { - return true; - } else if (other instanceof TypeToken>) { - return Objects.equals(this.type(), ((TypeToken>)other).type()); - } else { - return false; - } - } - - /** - * Returns a {@link String} representation of this {@link - * TypeToken}. - * - *This method returns a value equal to that returned by {@link - * Type#getTypeName() this.type().getTypeName()}.
- * - *This method never returns {@code null}.
- * - *This method produces a determinate - * value.
- * - *This method is idempotent.
- * - *This method is safe for concurrent use by multiple - * threads.
- * - * @return a {@link String} representation of this {@link - * TypeToken}; never {@code null} - */ - @Override // Object - public String toString() { - Type type = this.type(); - return type == null ? "null" : type.getTypeName(); - } - - /** - * Returns the type erasure for the supplied {@link Type} according - * to the rules of the Java Language - * Specification, section 4.6. - * - *This method may return {@code null}.
- * - *This method produces a determinate - * value.
- * - *This method is idempotent.
- * - *This method is safe for concurrent use by multiple - * threads.
- * - * @param type the {@link Type} for which the corresponding type - * erasure is to be returned; may be {@code null} in which case - * {@code null} will be returned - * - * @return a {@link Class}, or {@code null} if a suitable {@link - * Class}-typed type erasure could not be determined, indicating - * that the type erasure is the supplied {@link Type} itself - */ - private static final Class> erase(Type type) { - // https://docs.oracle.com/javase/specs/jls/se11/html/jls-4.html#jls-4.6 - // 4.6. Type Erasure - // - // Type erasure is a mapping from types (possibly including - // parameterized types and type variables) to types (that are - // never parameterized types or type variables). We write |T| - // for the erasure of type T. The erasure mapping is defined - // as follows: - // - // The erasure of a parameterized type (§4.5) G