August 2017
Intermediate to advanced
440 pages
10h
English
Kotlin generates multiple JVM bytecode elements from a single property (private field, getter, and setter). Sometimes, the framework annotation processor or the reflection-based library requires a particular element to be defined as a public field. A good example of this behavior is the JUnit test framework. It requires rules to be provided through a test class field or a getter method. We may encounter this problem when defining ActivityTestRule or Mockito's (mocking framework for unit tests) Rule annotation:
@Rule
val activityRule = ActivityTestRule(MainActivity::class.Java)
The preceding code annotates the Kotlin property that JUnit won't recognize, so ActivityTestRule can't be properly initialized. The JUnit annotation ...
Read now
Unlock full access