Class LambdaSafe


  • public final class LambdaSafe
    extends java.lang.Object
    Utility that can be used to invoke lambdas in a safe way. Primarily designed to help support generically typed callbacks where class cast exceptions need to be dealt with due to class erasure.
    Since:
    1.2.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LambdaSafe.Callback<C,​A>
      Represents a single callback that can be invoked in a lambda safe way.
      static class  LambdaSafe.Callbacks<C,​A>
      Represents a collection of callbacks that can be invoked in a lambda safe way.
      static class  LambdaSafe.InvocationResult<R>
      The result of a callback which may be a value, null or absent entirely if the callback wasn't suitable.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <C,​A>
      LambdaSafe.Callback<C,​A>
      callback​(java.lang.Class<C> callbackType, C callbackInstance, A argument, java.lang.Object... additionalArguments)
      Start a call to a single callback instance, dealing with common generic type concerns and exceptions.
      static <C,​A>
      LambdaSafe.Callbacks<C,​A>
      callbacks​(java.lang.Class<C> callbackType, java.util.Collection<? extends C> callbackInstances, A argument, java.lang.Object... additionalArguments)
      Start a call to callback instances, dealing with common generic type concerns and exceptions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • callback

        public static <C,​A> LambdaSafe.Callback<C,​A> callback​(java.lang.Class<C> callbackType,
                                                                          C callbackInstance,
                                                                          A argument,
                                                                          java.lang.Object... additionalArguments)
        Start a call to a single callback instance, dealing with common generic type concerns and exceptions.
        Type Parameters:
        C - the callback type
        A - the primary argument type
        Parameters:
        callbackType - the callback type (a functional interface)
        callbackInstance - the callback instance (may be a lambda)
        argument - the primary argument passed to the callback
        additionalArguments - any additional arguments passed to the callback
        Returns:
        a LambdaSafe.Callback instance that can be invoked.
      • callbacks

        public static <C,​A> LambdaSafe.Callbacks<C,​A> callbacks​(java.lang.Class<C> callbackType,
                                                                            java.util.Collection<? extends C> callbackInstances,
                                                                            A argument,
                                                                            java.lang.Object... additionalArguments)
        Start a call to callback instances, dealing with common generic type concerns and exceptions.
        Type Parameters:
        C - the callback type
        A - the primary argument type
        Parameters:
        callbackType - the callback type (a functional interface)
        callbackInstances - the callback instances (elements may be lambdas)
        argument - the primary argument passed to the callbacks
        additionalArguments - any additional arguments passed to the callbacks
        Returns:
        a LambdaSafe.Callbacks instance that can be invoked.