Function types versus arrays

Howard Lovatt howard.lovatt at iee.org
Mon Feb 15 13:57:11 PST 2010


Neal Gafter gave an array example on his blog:

http://gafter.blogspot.com/

Using:

http://www.artima.com/weblogs/viewpost.jsp?thread=278567

It is translated to:

    // 1. #void()[] arrayOfFunction = new #void()[1];
    _Callable_void[] arrayOfFunction = new _Callable_void[1];
    // 2. Object[] objectArray = arrayOfFunction;
    Object[] objectArray = arrayOfFunction; // No translation!
    // 3. objectArray[0] = #(){ throw new IOException(); };
    objectArray[0] = new _Callable_void_throws_IOException() {
      @Override public void callPrimitive() throws IOException { throw
new IOException(); }
    }; // Throws ArrayStoreException
    // 4. arrayOfFunction[0].(); // invoke the function out of the array
    arrayOfFunction[0].callPrimitive();

Line 3 throws an array store exception, as you would expect, because
the array is of type _Callable_void[] and you are attempting to put in
a _Callable_void_throws_IOException. Therefore using Reified Lambdas
the example works as expected.

  -- Howard.


More information about the lambda-dev mailing list