Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin-allopen plugin + @JvmField on a val not final enough

I am testing a new kotlin-allopen and kotlin-spring plugins under Kotlin 1.0.6.

In one of my @Transactional-annotated classes I have a field:

@JvmField val foo = null

When I try to build the project, I get:

Error:(45, 5) Kotlin: JvmField can only be applied to final property

Is there any proper way of dealing with this? My real-life code needed @JvmField because of the JUnit's @Rule. Managed to "solve" the problem by removing a @JvmField and annotating a getter instead. Not sure if a bug or a feature.

like image 520
Grzegorz Piwowarek Avatar asked Jan 04 '17 06:01

Grzegorz Piwowarek


1 Answers

I got the official solution.

In such case, finality provided by val is not enough. It turns out you need explicitly add final keyword there and this is not considered a bug.

@JvmField final val foo = null
like image 148
Grzegorz Piwowarek Avatar answered Nov 15 '22 06:11

Grzegorz Piwowarek