In Kotlin M13, this was an acceptable way to create a JUnit rule:
@Rule @publicField val temp = TemporaryFolder()
Now that @publicField
has been deprecated, how else can this be achieved? The IDE hint suggests replacing @publicField
with lateinit
, but lateinit val
's are no longer allowed, and I'm not sure this would help even if they were.
The answer as of Kotlin 1.0 is as follows:
@Rule @JvmField val temp = TemporaryFolder()
@JvmField
exposes the backing field with the same visibility as the property, ergo a public field for the JUnit rule to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With