Does Kotlin generated byte code affect the method count?

Mel :

For example, if I use

methodReference = ::method

rather than

methodReference = { method(it) }

decompiled code will contain getOwner, getName, getSignature methods in Java code, due to reflection. Do these methods counted against 64k limit ?

Eugene Petrenko :

The methods are counted, only if they are not removed by proguard/R8

An example

  fun method(t : Any) {}
  val reference1: KFunction1<Any, Unit> = ::method
  val reference2: (Any) -> Unit = { method(it) }

For the reference1 the bytecode (decompiled to Java) would be:

   @NotNull
   final KFunction reference1 = new Function1((X)this) {
      // $FF: synthetic method
      // $FF: bridge method
      public Object invoke(Object var1) {.. }
      public final void invoke(@NotNull Object p1) {..}
      public final KDeclarationContainer getOwner() {..}
      public final String getName() {..}
      public final String getSignature() {..}
   };

for the lambda (or reference2) the equivalent java code is:

   @NotNull
   final Function1 reference2 = (Function1)(new Function1() {
      // $FF: synthetic method
      // $FF: bridge method
      public Object invoke(Object var1) {..}
      public final void invoke(@NotNull Object it) {..}
   });

So the difference is 4 +1 for method reference and 1 +1 for lambda, where +1 comes from the the bridge method invoke(t:Any)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=77521&siteId=1