Reified Lambda Functions

Howard Lovatt howard.lovatt at iee.org
Fri Jan 8 04:43:03 PST 2010


Answers inline:

2010/1/7 Neal Gafter <neal at gafter.com>

> Am I to understand that List<#String()> is always represented as
> List<Callable$0<String>>, so that pulling something out of such a list
> always requires the invocation of one of your cast operation?
>

If you go from generic to reified or reified
to contravariantly-overridden reified then there is a conversion operation.
In other cases there is no conversion. I would contend that the other cases
are the most common and therefore in general no conversion is applied. There
is also an optimization included, if you go from reified to generic and then
back to reified no new object is created (it tests the type to check if a
wrapping is needed).

>
> If so, it would appear that the cast operation is "inventing" type
> information out of thin air from unreified data, and doing so where
> (in the presence of heap pollution) that data is incorrect.  Is that
> right?
>

If the heap is polluted, e.g.:

  static void heapPollution() {
    List l = new ArrayList<Integer>();
    l.add(1);
    List<$Callable$0<? extends String>> alphabet = l;
    $Callable$String firstLetter =
$From$0$String$$To$String.instance(alphabet.get(0));
    System.out.println("Polluted firstLetter = " + firstLetter.call());
  }

Then you get a class cast exception when the 'instance' method is called.
Therefore no different than currently occurs with heap pollution (a nice
feature, that is coincidental, is that the heap pollution is detected
early).

Thanks for the feedback,

 -- Howard.

>
> -Neal
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>



-- 
 -- Howard.


More information about the lambda-dev mailing list