Kotlin JUnit Rules

In Kotlin M13, this was an acceptable way to create a JUnit rule:

@Rule @publicField val temp = TemporaryFolder()

Now that @publicField out of date, how else can this be achieved? The IDE hint suggests replacing @publicField with lateinit , but lateinit val no longer allowed, and I'm not sure if that would help, even if they were.

+8
kotlin
source share
2 answers

The answer to Kotlin 1.0 is as follows:

 @Rule @JvmField val temp = TemporaryFolder() 

@JvmField expands the support field with the same visibility as the property, ergo is the public field for using the JUnit rule.

+12
source share

Just guessing, but the following may work (with var ):

 @Rule lateinit var temp = TemporaryFolder() 

I would ask to ask kotlin slack for http://t.co/xpQXUKaDvP This is currently the fastest way to fix anything.

-3
source share

All Articles