kotlin中!!.和?.的区别
在Kotlin中!!跟?都是用于判断空参数异常的
?.意思是这个参数可以为空,并且程序继续运行下去
!!.的意思是这个参数如果为空,就抛出异常
Kotlin 中的数字没有隐式拓宽转换
有 Double 参数的函数只能对 Double 值调用,而不能对 Float、 Int 或者其他数字值调用
fun main() {fun printDouble(d: Double) { print(d) }val i = 1val d = 1.1val f = 1.1fprintDouble(d)// printDouble(i) // 错误:类型不匹配// printDouble(f) // 错误:类型不匹配}
