I want to call a overloaded java-function from Kotlin. I want to use a null
for parameter that significant to a overload resolution.
How to specify IntArray
type for null
value?
I don't like a solution with additional varibale of common type.
Instead of a variable just cast it, i.e. null as IntArray?
, e.g.:
origImg.data.getSamples(0, 0, origImg.width, origImg.height, 0, null as IntArray?)
Note that this is the same behaviour as in Java, where you also needed to cast null
, e.g. (int[]) null
, to call the appropriate overloaded method.
You could build a function that gives you a ~typed null
(if it doesn't exist yet) with a reified type:
inline fun <reified T>typedNull(): T? = null
and calling it with:
typedNull<IntArray>()
But then again, null as IntArray?
is clear enough I think and people know it already.
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