Class LambdaTypeBaker


  • public final class LambdaTypeBaker
    extends Object
    • Method Detail

      • bakeLambdaType

        public static <T> T bakeLambdaType​(T originalOp,
                                           Type reifiedType)
        Used to enrich a lambda expression with its generic type. Its usage is necessary in order to find Ops that could take this lamdba expression as an argument.

        Suppose, for example, that a user has written a lambda Computers.Arity1<Double, Double> computer, but a user wishes to have a Computers.Arity1<Iterable<Double>, Iterable<Double>>. They know of an Op in the OpEnvironment that is able to adapt computer so that it is run in a parallel fashion. They cannot simply call

        
         op("engine.adapt").input(computer).outType(
         	new Nil&lt;Computers.Arity1&lt;Iterable&lt;Double&gt;, Iterable&lt;Double&gt;&gt;&gt;()
         	{}).apply()
         
        since the type parameters of computer are not retained at runtime.

        bakeLambdaType should be used as a method of retaining that fully reified lambda type so that the lambda can be used

        Note: bakeLambdaType does not need to be used with anonymous subclasses; these retain their type parameters at runtime. It is only lambda expressions that need to be passed to this method.

        Type Parameters:
        T - The type of the op instance to enrich.
        Parameters:
        originalOp - The op instance to enrich.
        reifiedType - The intended generic type of the object to be known at runtime.
        Returns:
        An enriched version of the object with full knowledge of its generic type.