Should serialVersionUID have @JvmStatic by default?

I suddenly found that my Kotlin code converted from Java contained such lines:
companion object {
private val serialVersionUID = -7612510838405643774L
}

There is no @JvmStatic modifier. Is this a defect of the code converter?

Yes, the converter should be improved to handle that case. I’ve filed an issue for this.

This issue, that you mentioned has been fixed. But on latest IDEA kotlin plugin 1.1.0-release with kotlin 1.1.0 i see that serialVersionUID static java field will be converted into:

companion object {
    private val serialVersionUID = 6817358179680149735L
}

instead of

companion object {
    const val serialVersionUID = 6817358179680149735L
}

Anyway, just different codegeneration :slight_smile:

@skovtunenko, the expected result of conversion is const val serialVersionUID in companion when the class is Serializable and plain val when it isn’t.
If it is not like that in your case, please open an issue.

Ok, i’ve created one: https://youtrack.jetbrains.com/issue/KT-16662

Issue related to inherited base class that implemented Serializable java interface.

1 Like