when converting java file to kotlin?
this result occurs compile error
k
Kevin Del Castillo
12/19/2022, 2:55 PM
The convert from Java to Kotlin, is not perfect, it cannot know if the static function will still be used in Java code, hence no need to add
@JvmStatic
, I guess it's more of an optional step, or an edge case that hasn't been actually considered.
Said this you should always check the resulting Kotlin file for any inconsistency, as already mentioned transforming it is not perfect so there might be still things you'd like to change afterwards.
r
Roach
12/19/2022, 3:13 PM
If you use the old kotlin version, it automatically attaches the @JvmStatic annotation.
i think it changed recently.
j
Joffrey
12/19/2022, 3:15 PM
The thing is, it turned your class into an
object
because everything in it was static. This makes it a singleton. Therefore the problem is not really in the missing
@JvmStatic
but rather in the access on java side. Use
Shortlists.INSTANCE.sorted(...)
instead
r
Roach
12/19/2022, 3:34 PM
yep. i understand your answer. but I wonder why it changed to break the compilation