provide simple method to wrap a given type to the Typed interface

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1525722 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Matthew Jason Benson 2013-09-23 22:42:03 +00:00
parent 327593c27d
commit 1cbba96f16
2 changed files with 22 additions and 0 deletions

View File

@ -1540,6 +1540,22 @@ public class TypeUtils {
return buf.append(':').append(typeVariableToString(var)).toString();
}
/**
* Wrap the specified {@link Type} in a {@link Typed} wrapper.
*
* @param T inferred generic type
* @param type to wrap
* @return Typed<T>
*/
public static <T> Typed<T> wrap(final Type type) {
return new Typed<T>() {
@Override
public Type getType() {
return type;
}
};
}
private static String classToString(Class<?> c) {
final StringBuilder buf = new StringBuilder();

View File

@ -716,6 +716,12 @@ public class TypeUtilsTest<B> {
Assert.assertEquals(getClass().getName() + ":B", TypeUtils.toLongString(getClass().getTypeParameters()[0]));
}
@Test
public void testWrap() {
final Type t = getClass().getTypeParameters()[0];
Assert.assertTrue(TypeUtils.equals(t, TypeUtils.wrap(t).getType()));
}
public Iterable<? extends Map<Integer, ? extends Collection<?>>> iterable;
public static <G extends Comparable<G>> G stub() {