instantiationexception

Why am I having this InstantiationException in Java when accessing final local variables?

I was playing with some code to make a "closure like" construct ( not working btw ) Everything looked fine but when I tried to access a final local variable in the code, the exception InstantiationException is thrown. If I remove the access to the local variable either by removing it altogether or by making it class attribute instead...

InstantiationException on newInstance of generated anonymous class

Update: this is more-or-less a dupe, and it turns out to be compiler magic adding a constructor to pass in the local variable in build2. Given an interface like such: public interface IFoo { public int get(); } The code below prints 1, 1, 2 and then throws an exception when trying to call getClass().newInstance() on the value ...