Class GenericsUtils

java.lang.Object
org.springframework.cloud.stream.reflection.GenericsUtils

public final class GenericsUtils extends Object
Internal utilities for handling generics.
Author:
Marius Bogoevici, Gary Russell
  • Method Details

    • getParameterType

      public static Class<?> getParameterType(Class<?> evaluatedClass, Class<?> interfaceClass, int position)
      For a specific class that implements or extends a parameterized type, return the parameter of that interface at a given position. For example, for this class:
       
       class MessageChannelBinder implements Binder<MessageChannel, ?, ?>
        
       
       getParameterType(MessageChannelBinder.class, Binder.class, 0);
        
      will return Binder
      Parameters:
      evaluatedClass - the evaluated class
      interfaceClass - the parametrized interface
      position - the position
      Returns:
      the parameter type if any
      Throws:
      IllegalStateException - if the evaluated class does not implement the interface or
    • checkCompatiblePollableBinder

      public static boolean checkCompatiblePollableBinder(Binder binderInstance, Class<?> bindingTargetType)
      Return the generic type of PollableSource to determine if it is appropriate for the binder. e.g., with PollableMessageSource extends PollableSource<MessageHandler> and AbstractMessageChannelBinder implements PollableConsumerBinder<MessageHandler, C> We're checking that the the generic type (MessageHandler) matches.
      Parameters:
      binderInstance - the binder.
      bindingTargetType - the binding target type.
      Returns:
      true if found, false otherwise.