public final class Types extends Object
Modifier and Type | Method and Description |
---|---|
static Class<?> |
box(Class<?> type)
Return the boxed version of the given type if the type is primitive.
|
static Type |
box(Type type)
Return the boxed version of the given type if the type is primitive.
|
static Class<?> |
erase(Type type)
Compute the erasure of a type.
|
static ClassLoader |
getDefaultClassLoader()
Deprecated.
Use
ClassLoaders.inferDefault() instead. |
static Class<?> |
getProvidedType(Class<? extends javax.inject.Provider<?>> providerClass)
Get the type that is provided by a given implementation of
Provider . |
static Class<?> |
getProvidedType(javax.inject.Provider<?> provider)
Get the type that is provided by the Provider instance.
|
static int |
getTypeDistance(Class<?> child,
Class<?> parent)
Return the type distance between the child and parent types.
|
static boolean |
hasNullableAnnotation(Annotation[] annotations)
Return true if the array of Annotations contains an Annotation with a
simple name of 'Nullable'.
|
static boolean |
isInstantiable(Class<?> type)
Return true if the type is not abstract and not an interface, and has
a constructor annotated with
Inject or its only constructor
is the default constructor. |
static Type |
parameterizedType(Class<?> type,
Type... arguments)
Create a parameterized type wrapping the given class and type arguments.
|
static boolean |
shouldBeInstantiable(Class<?> type)
Return true if the type is not abstract and not an interface.
|
public static Type parameterizedType(Class<?> type, Type... arguments)
type
- arguments
- public static Type box(Type type)
type
- The possibly unboxed typepublic static Class<?> box(Class<?> type)
type
- The possibly unboxed typepublic static Class<?> erase(Type type)
type
- The type to erase.IllegalArgumentException
- if type is unerasable (e.g.
it is a type variable or a wildcard).public static int getTypeDistance(@Nonnull Class<?> child, @Nonnull Class<?> parent)
child
- The child typeparent
- The parent typeIllegalArgumentException
- if child
is not a subtype of parent
.public static Class<?> getProvidedType(Class<? extends javax.inject.Provider<?>> providerClass)
Provider
.providerClass
- The provider's classIllegalArgumentException
- if the class doesn't actually implement
Providerpublic static Class<?> getProvidedType(javax.inject.Provider<?> provider)
provider
- The provider instance queriedgetProvidedType(Class)
public static boolean isInstantiable(Class<?> type)
Inject
or its only constructor
is the default constructor.type
- A class typepublic static boolean shouldBeInstantiable(Class<?> type)
Return true if the type is not abstract and not an interface. This will
return true essentially when the class "should" have a default
constructor or a constructor annotated with @Inject
to be
used properly.
As another special rule, if the input type is Void
, false is
returned because for most intents and purposes, it is not instantiable.
type
- The type to testpublic static boolean hasNullableAnnotation(Annotation[] annotations)
annotations
- Array of annotations, e.g. from a setter or
constructor@Deprecated public static ClassLoader getDefaultClassLoader()
ClassLoaders.inferDefault()
instead.Copyright © 2016 GroupLens Research. All rights reserved.