Skip to content

Question on using a UDT as a struct field from another project #204

Answered by Jolanrensen
barrettc asked this question in Q&A
Discussion options

You must be logged in to vote

So, it all comes down to getting the instance of the Scala singleton from Kotlin, right?
Well, as you've discovered, Scala is a bit less friendly towards other JVM languages compared to Kotlin. Using MODULE$ is actually the official way to access singleton instances.

However, since we're using Kotlin, we can make it a tiny bit simpler, without using reflection, thanks to being able to backtick names:

val struct = DataTypes.createStructType(
    arrayOf(
        DataTypes.createStructField(
            "name",
            DataTypes.StringType,
            false
        ),
        DataTypes.createStructField(
            "out",
            `EmbeddedListType$`.`MODULE$`,
            false

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@barrettc
Comment options

@Jolanrensen
Comment options

Answer selected by barrettc
@barrettc
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants