https://kotlinlang.org logo
#stdlib
Title
# stdlib
k

kz

04/26/2018, 3:07 PM
(This is probably not the right channel but I'm not sure what would be) How does the Kotlin compiler decide when the class generated for a lambda includes the
this
reference? I'm using Apache Spark and my jobs is failing due to the task not being serializable because one of my lambda's generated class includes the
SparkJob
reference (which I don't want
Serializable
). The reference is included as a class field even though it's not actually accessed. Then in my other spark jobs I have plenty other lambdas that also don't access the
this
reference and properly do not have that code generated.
a

Andreas Sinz

04/26/2018, 4:00 PM
that question is more of #general question 🙂 do you access anything inside the lambda that's outside of the lambda?
k

kz

04/26/2018, 4:06 PM
I do not. A colleague of mine just had a crazy idea though. We split up the expression into 2 lines and all of a sudden Kotlin was no longer capturing the
this
reference. I will try to come up with a small example but our current theory is that Kotlin will capture in the lambda any reference that appears on the line the lambda is defined (even if it is not actually used in the lambda)
I thought about #general but the churn through there is extremely fast. The #compiler channel seems dead.
a

Andreas Sinz

04/26/2018, 4:07 PM
can you show us the code of the lambda?
k

kz

04/26/2018, 4:08 PM
I need to distill it down to something smaller. There is a lot of junk there right now that would obfuscate the issue too much. I will post something soon.
When I try to simplify things code generation changes to an anonymous inner class instead of a named class. I'm dropping this for now until I run into it again.
d

dsavvinov

04/27/2018, 9:43 AM
@kz JFYI, some of JB folks try to monitor #compiler channel (on the best-effort basis), but messages history gets cleared pretty fast because of Slack limitations, that's why it looks dead 🙂
k

kz

04/27/2018, 2:02 PM
🙂 Makes sense. Should I run into this again I will post there.
2 Views