kz

    kz

    4 years ago
    (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

    4 years ago
    that question is more of #general question 🙂 do you access anything inside the lambda that's outside of the lambda?
    kz

    kz

    4 years ago
    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

    4 years ago
    can you show us the code of the lambda?
    kz

    kz

    4 years ago
    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.
    dsavvinov

    dsavvinov

    4 years ago
    @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 🙂
    kz

    kz

    4 years ago
    🙂 Makes sense. Should I run into this again I will post there.