com.nhaarman.mockito_kotlin.createinstance.NullCaster.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-kotlin Show documentation
Show all versions of mockito-kotlin Show documentation
Using Mockito with Kotlin.
The newest version!
package com.nhaarman.mockito_kotlin.createinstance
import kotlin.reflect.KClass
/**
* Uses a quirk in the bytecode generated by Kotlin
* to cast [null] to a non-null type.
*
* See https://youtrack.jetbrains.com/issue/KT-8135.
*/
internal class NullCaster : NonNullProvider {
override fun createInstance(kClass: KClass): T {
return castNull()
}
private fun castNull(): T = null as T
}