Package ratpack.util
Class Types
- java.lang.Object
-
- ratpack.util.Types
-
public abstract class Types extends java.lang.ObjectStatic utility methods for dealing with types.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> Tcast(java.lang.Object o)Simply casts the argument toT.static <T> com.google.common.reflect.TypeToken<T>intern(com.google.common.reflect.TypeToken<T> typeToken)Intern the given type token.static <T> com.google.common.reflect.TypeToken<java.util.List<T>>listOf(java.lang.Class<T> type)Creates a type token for a list of of the given type.static <T> com.google.common.reflect.TypeToken<Promise<T>>promiseOf(com.google.common.reflect.TypeToken<T> type)Deprecated.since 1.5, no replacement.static <T> com.google.common.reflect.TypeToken<Promise<T>>promiseOf(java.lang.Class<T> type)Deprecated.since 1.5, no replacement.static <T> com.google.common.reflect.TypeToken<T>token(java.lang.Class<T> clazz)Create a type token for the given class.static com.google.common.reflect.TypeToken<?>token(java.lang.reflect.Type type)Create a type token for the given runtime type.
-
-
-
Method Detail
-
cast
public static <T> T cast(java.lang.Object o)
Simply casts the argument toT.This method will throw
ClassCastExceptionifois not compatible withT.- Type Parameters:
T- the target type- Parameters:
o- the object to cast- Returns:
- the input object cast to the target type
-
token
public static com.google.common.reflect.TypeToken<?> token(java.lang.reflect.Type type)
Create a type token for the given runtime type. This method should be preferred overTypeToken.of(Type)as the result may be interned when not in development.- Parameters:
type- the type- Returns:
- a type token for the given type
- Since:
- 1.1
-
token
public static <T> com.google.common.reflect.TypeToken<T> token(java.lang.Class<T> clazz)
Create a type token for the given class. This method should be preferred overTypeToken.of(Class)as the result may be interned when not in development.- Type Parameters:
T- the type- Parameters:
clazz- the class- Returns:
- a type token for the given class
- Since:
- 1.1
-
intern
public static <T> com.google.common.reflect.TypeToken<T> intern(com.google.common.reflect.TypeToken<T> typeToken)
Intern the given type token.- Type Parameters:
T- the type- Parameters:
typeToken- the type token to intern- Returns:
- the given type token interned
- Since:
- 1.5
-
listOf
public static <T> com.google.common.reflect.TypeToken<java.util.List<T>> listOf(java.lang.Class<T> type)
Creates a type token for a list of of the given 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>>() {}); } }- Type Parameters:
T- the list element type- Parameters:
type- the list element type- Returns:
- a type token for a list of of the given type.
-
promiseOf
@Deprecated public static <T> com.google.common.reflect.TypeToken<Promise<T>> promiseOf(java.lang.Class<T> type)
Deprecated.since 1.5, no replacement.Creates a type token for a promise of of the given 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 { @SuppressWarnings("deprecation") public static void main(String... args) { assertEquals(Types.promiseOf(String.class), new TypeToken<Promise<String>>() {}); } }- Type Parameters:
T- the promise element type- Parameters:
type- the promise element type- Returns:
- a type token for a promise of of the given type.
-
promiseOf
@Deprecated public static <T> com.google.common.reflect.TypeToken<Promise<T>> promiseOf(com.google.common.reflect.TypeToken<T> type)
Deprecated.since 1.5, no replacement.Creates a type token for a promise of the given 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 { @SuppressWarnings("deprecation") public static void main(String... args) { assertEquals( Types.promiseOf(new TypeToken<List<String>>() {}), new TypeToken<Promise<List<String>>>() {} ); } }- Type Parameters:
T- the promise element type- Parameters:
type- the promise element type- Returns:
- a type token for a promise of of the given type.
-
-