Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

when I declare a property in a class as following:

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

and then decompiled as following:

......

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

......

what does the (Function0)null.INSTANCE stand for? I think it will be :

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

but it doesn't ,why?

Thanks!

like image 787
xzw happy Avatar asked Jul 03 '17 03:07

xzw happy


1 Answers

Decompiler not showing the correct result: e.g. when doing it with 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;
}
like image 179
guenhter Avatar answered Sep 18 '22 16:09

guenhter