org.sonatype.guice.bean.reflect
Class TypeParameters

java.lang.Object
  extended by org.sonatype.guice.bean.reflect.TypeParameters

public final class TypeParameters
extends Object

Utility methods for dealing with generic type parameters and arguments.


Method Summary
static com.google.inject.TypeLiteral<?>[] get(com.google.inject.TypeLiteral<?> typeLiteral)
          Get all type arguments from a generic type, for example [Foo,Bar] from Map<Foo,Bar>.
static com.google.inject.TypeLiteral<?> get(com.google.inject.TypeLiteral<?> typeLiteral, int index)
          Get an indexed type argument from a generic type, for example Bar from Map<Foo,Bar>.
static boolean isAssignableFrom(com.google.inject.TypeLiteral<?> superLiteral, com.google.inject.TypeLiteral<?> subLiteral)
          Determines if the sub-type can be converted to the generic super-type via an identity or widening conversion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static com.google.inject.TypeLiteral<?>[] get(com.google.inject.TypeLiteral<?> typeLiteral)
Get all type arguments from a generic type, for example [Foo,Bar] from Map<Foo,Bar>.

Parameters:
typeLiteral - The generic type
Returns:
Array of type arguments

get

public static com.google.inject.TypeLiteral<?> get(com.google.inject.TypeLiteral<?> typeLiteral,
                                                   int index)
Get an indexed type argument from a generic type, for example Bar from Map<Foo,Bar>.

Parameters:
typeLiteral - The generic type
index - The argument index
Returns:
Indexed type argument; TypeLiteral<Object> if the given type is a raw class

isAssignableFrom

public static boolean isAssignableFrom(com.google.inject.TypeLiteral<?> superLiteral,
                                       com.google.inject.TypeLiteral<?> subLiteral)
Determines if the sub-type can be converted to the generic super-type via an identity or widening conversion.

Parameters:
superLiteral - The generic super-type
subLiteral - The generic sub-type
Returns:
true if the sub-type can be converted to the generic super-type; otherwise false
See Also:
Class.isAssignableFrom(Class)


Copyright © 2010-2011 Sonatype, Inc.. All Rights Reserved.