Tag: 铸件

Kotlin中“as”和“is”运算符有什么区别?

在Java中,我可以编写如下代码: void cast(A a) { if(a instanceof Person) { Person p = (Person) a; } } 在Kotlin,我该怎么办? as操作员还是操作员?

Kotlin为什么不执行自动types转换?

var a : Double a = Math.sin(10) // error: the integer literal does not conform to the expected type Double a = Math.sin(10.0) //This compiles successfully println(a) kotlin为什么不执行隐式types转换并强制我们传递确切types的数据? fun sin(value: Double): Double // at kotlin documentation

在使用arrayOfNulls时,是否可以删除Kotlin中未经检查的转换?

在Kotlin开发简单的主要队列的同时,我碰到了一个没有经过检查的警告,我无法摆脱: private val pq: Array = arrayOfNulls<Comparable>(capacity) as Array 以下是Kotlin优先级队列的完整源代码: class UnorderedMaxPQ<T : Comparable>(capacity: Int) { private val pq: Array = arrayOfNulls<Comparable>(capacity) as Array private var size = 0 fun isEmpty() = size == 0 fun size() = size fun insert(x: T) { pq[size++] = x } fun delMax(): T { var max = 0 […]