我尝试使用 kotlin 制作 MethodCall 类型判断函数,但它为我返回类型不匹配,我该如何解决?
import java.util.Objects
import io.flutter.plugin.common.MethodCall
class Utils private constructor() {
companion object {
fun getDoubleArgument(call: MethodCall, argument: String?): Double {
return try {
if (call.argument<Any>(argument) is Double) {
Objects.requireNonNull(call.argument<Double>(argument))!! // The call.argument return Double? type, but when I add !! assert, it report Unnecessary non-null assertion (!!).
} else if (call.argument<Any>(argument) is Long) {
val l = Objects.requireNonNull(call.argument<Long>(argument))
l!!.toDouble()
} else if ...
}