Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin JUnit Rules

Tags:

kotlin

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.

like image 915
Jonathan Schneider Avatar asked Oct 02 '15 03:10

Jonathan Schneider


1 Answers

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.

like image 87
Jonathan Schneider Avatar answered Oct 09 '22 07:10

Jonathan Schneider