public abstract class Types extends Object
Modifier and Type | Method and Description |
---|---|
static <T> T |
cast(Object o)
Simply casts the argument to
T . |
static <T> TypeToken<List<T>> |
listOf(Class<T> type)
Creates a type token for a list of of the given type.
|
static <T> TypeToken<Promise<T>> |
promiseOf(Class<T> type)
Creates a type token for a promise of of the given type.
|
static <T> TypeToken<Promise<T>> |
promiseOf(TypeToken<T> type)
Creates a type token for a promise of of the given type.
|
static <T> TypeToken<T> |
token(Class<T> clazz)
Create a type token for the given class.
|
static TypeToken<?> |
token(Type type)
Create a type token for the given runtime type.
|
public static <T> T cast(Object o)
T
.
This method will throw ClassCastException
if o
is not compatible with T
.
T
- the target typeo
- the object to castpublic static TypeToken<?> token(Type type)
TypeToken.of(Type)
as the result may be interned when not in development.type
- the typepublic static <T> TypeToken<T> token(Class<T> clazz)
TypeToken.of(Class)
as the result may be interned when not in development.T
- the typeclazz
- the classpublic static <T> TypeToken<List<T>> listOf(Class<T> type)
import ratpack.util.Types;
import com.google.common.reflect.TypeToken;
import java.util.List;
import static org.junit.Assert.*;
public class Example {
public static void main(String... args) {
assertEquals(Types.listOf(String.class), new TypeToken<List<String>>() {});
}
}
T
- the list element typetype
- the list element typepublic static <T> TypeToken<Promise<T>> promiseOf(Class<T> type)
import ratpack.util.Types;
import ratpack.exec.Promise;
import com.google.common.reflect.TypeToken;
import java.util.List;
import static org.junit.Assert.*;
public class Example {
public static void main(String... args) {
assertEquals(Types.promiseOf(String.class), new TypeToken<Promise<String>>() {});
}
}
T
- the promise element typetype
- the promise element typepublic static <T> TypeToken<Promise<T>> promiseOf(TypeToken<T> type)
import ratpack.util.Types;
import ratpack.exec.Promise;
import com.google.common.reflect.TypeToken;
import java.util.List;
import static org.junit.Assert.*;
public class Example {
public static void main(String... args) {
assertEquals(
Types.promiseOf(new TypeToken<List<String>>() {}),
new TypeToken<Promise<List<String>>>() {}
);
}
}
T
- the promise element typetype
- the promise element type