Class TypeReference<E>

java.lang.Object
org.axonframework.common.TypeReference<E>
Type Parameters:
E - The type of the component.

public abstract class TypeReference<E> extends Object
Represents a reference to a type of component, allowing for generic types to be specified without casting errors.
Since:
5.0.0
Author:
Mitchell Herrijgers
  • Field Details

    • type

      protected final Type type
  • Constructor Details

    • TypeReference

      protected TypeReference()
  • Method Details

    • fromClass

      public static <C> TypeReference<C> fromClass(Class<C> clazz)
      Constructs a TypeReference for the given clazz.
      Type Parameters:
      C - The clazz this TypeReference reflects.
      Parameters:
      clazz - The clazz of the TypeReference under construction.
      Returns:
      A new TypeReference instance of the given clazz.
    • fromType

      public static <C> TypeReference<C> fromType(Type type)
      Constructs a TypeReference for the given type.
      Type Parameters:
      C - The type this TypeReference reflects.
      Parameters:
      type - The type of the TypeReference under construction.
      Returns:
      A new TypeReference instance of the given type.
    • getTypeAsClass

      public Class<E> getTypeAsClass()
      Returns the class of the type of the component represented by this TypeReference.
      Returns:
      The class of the component.
    • getType

      public Type getType()
      Returns the type of the component represented by this TypeReference.
      Returns:
      The type of the component.
    • isAssignableFrom

      public boolean isAssignableFrom(TypeReference<?> other)
      Checks if this TypeReference is assignable from the other TypeReference.

      It takes generic parameters into account by first checking if the raw types match by means of Class.isAssignableFrom(Class), subsequently checking for compatibility of generic types by expecting an exact match of the types if any of this and other represent a parameterized type.

      Parameters:
      other - the other TypeReference to compare this to
      Returns:
      true if the other TypeReference is assignable from this TypeReference.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object