Why is kotlin lambda decompiled to java code (Function0) null.INSTANCE

when i declare a property on a class like this:

class xx{
    var b:()->Boolean={false}
}

      

and then decompiled like this:

......

public xxx() {
    this.b = (Function0)null.INSTANCE;
}

......

      

what does (Function0) null.INSTANCE mean? I think it would be:

this.b= new Function0() {
        public final Object invoke() {
                 return false;
         }
};

      

but it is not, why?

Thank!

+3


source to share


1 answer


The decompiler does not show the correct result: eg. when you do it from JD-GUI you get:



final class xx$b$1 extends Lambda implements kotlin.jvm.functions.Function0<Boolean> { 
  public final boolean invoke() { return false; }

  public static final 1 INSTANCE = new 1();
  xx$b$1()
  {
    super(0);
  }
}


public final class xx { 
  // ... getter and setter
  private Function0<Boolean> b = (Function0)xx.b.1.INSTANCE;
}

      

+2


source







All Articles