public final class Cast extends Object
as(Object, Class) performs a cast operation, returning null if a
cast is not valid.
This allows illegal cast syntax to be more elegant and brief - a null check
as opposed to a try/catch.
is(Object, Class) and its variants allow for quick type checking.
Usually as(Object, Class) allows for more succinct code, but there
are scenarios where type, or multiple type checking are useful.
| Modifier and Type | Method and Description |
|---|---|
static <S,T> S |
as(T t,
Class<S> s)
Performs a cast operation of the parameter t to the type defined by the
class s, or null if no legal cast can be made.
|
static <T> boolean |
is(T t,
Class<?>... s) |
static <S,T> boolean |
is(T t,
Class<S> s) |
static <T> boolean |
is(T t,
Iterable<Class<?>> s) |
public static <S,T> S as(T t,
Class<S> s)
Performs a cast operation of the parameter t to the type defined by the class s, or null if no legal cast can be made.
This allows illegal cast syntax to be more elegant and brief - a null check as opposed to a try/catch.
Returns null if t is null, in this case no type can be inferred.
S - T - t - object to casts - Class to cast the parameter t topublic static <S,T> boolean is(T t,
Class<S> s)
t - instance who's type is to be testeds - a type as a Classpublic static <T> boolean is(T t,
Class<?>... s)
t - instance who's type is to be testeds - one or more ClassesCopyright © 2013 Atomic Leopard. All Rights Reserved.