Questionable compilation failure

Remi Forax forax at univ-mlv.fr
Wed Sep 18 09:34:50 PDT 2013


On 09/18/2013 06:18 PM, Millies, Sebastian wrote:
> Hello there,
>
> on my Windows 7 (64bit) box, the following does not compile with the developer preview build (b 106). Should it?
>
> import java.util.function.Supplier;
>
> public class SupplierTest {
>
>      class Concrete<T> implements Supplier<Concrete<T>> {
>          @Override
>          public Concrete<T> get() {
>              return this;
>          }
>      }
>
>      interface Test  {
>          default void doSomething() {
>               new Concrete<String>();   // <-----
>          }
>      }
>
> }
>
> The error message is:
>
> \SupplierTest.java:16: error: non-static variable this cannot be referenced from a static context
> new Concrete<String>();
> ^
>
> However, a default method implementation is not static, or is it? (Perhaps it's just the error
> message that's confusing me.)

It's maybe a bug, at least the error message is misleading.

You declare Concrete as a *non-static* inner class, so it needs an 
instance of SupplierTest
to be able to create an instance of Concrete.

here, new Concrete<String>() is transformed to this.new Concrete<String>(),
so you create to create a Concrete with an instance of Test and not with 
an instance of SupplierTest.

I suppose that you just forget to declare Concrete static ?

cheers,
Rémi




>
>
> n  Sebastian
>
>
>
>
> Software AG - Sitz/Registered office: Uhlandstra?e 12, 64297 Darmstadt, Germany - Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com
>
>



More information about the lambda-dev mailing list