Huh, I see that function references generate one c...
# compiler
t
Huh, I see that function references generate one class per use site for JVM. Is this something unavoidable? The reference has to store the receiver, so I guess a new instance creation is unavoidable, but I guessed it will be one general class, not one per use site.
Copy code
class E {
    fun b1() = Unit
    val b = B(this::b1)
    val c = B(this::b1)
}

class B(
    val func: () -> Unit
)
Results in 4 classes: • B.class • E.class • E$b$1.class • E$c$1.class In my specific use case I have a number of compiler plugin generated functions I pass, like in the example below. I could write a workaround by generating one function that gets the instance of E and an integer index and uses a
when
to select the appropriate function. But that feels like a bit forced.
Copy code
class E {
   fun a1() = Unit
   fun a2() = Unit
   init {
      B(this::a1)
      B(this::a2)
   }
}