Function types versus arrays

Neal Gafter neal at gafter.com
Wed Feb 17 14:48:27 PST 2010


On Wed, Feb 17, 2010 at 2:39 PM, Joshua Bloch <jjb at google.com> wrote:
> Neal,
> I'm having a bit of trouble understanding this.  I'm not endorsing any
> implementation scheme, but you say that this program necessarily breaks the
> type system:
>
> public void main(String[] args) {
>     #void()[] arrayOfFunction = new #void()[1];
>     Object[] objectArray = arrayOfFunction;
>     objectArray[0] = #(){ throw new IOException(); };  // **
>     arrayOfFunction[0].(); // invoke the function out of the array
> }
>
> It would appear that the starred line should generate an ArrayStoreException
> at runtime, as #void()(throws IOException) isn't a subtype of #void().  I
> understand that it might take a sophisticated implementation to enforce
> this. What am I missing?
>          Josh

Presuming the source were legal, that's exactly right.  We're
exploring how such a "sophisticated implementation" breaks
compatibility with the existing language specification (thus the
"implementation" focus of the discussion), with the consequence that
the source must not be allowed.

Cheers,
Neal


More information about the lambda-dev mailing list