fun main() {
val highScores = listOf(4000, 2000, 10200, 12000, 9030)
}
.withIndex()
.forEachIndexed()
.forEach()
.forIndexes()
abstract class Aircraft {
init { println("Aircraft = ${getName()}") }
abstract fun getName(): String
}
class Airplane(private val name: String) : Aircraft() {
override fun getName(): String = name
}
fun add(a: Int, b: Int): Int {
return a + b
}
println(add(5,10).invoke())
println(::add.invoke(5, 10))
println(::add.invoke{5, 10})
println(add.invoke(5,10))
fun static main(){}
fun main(){}
fun Main(){}
public static void main(){}
fun showHashCode(obj: Any){
println("${obj.hashCode()}")
}
fun main() {
showHashCode(1)
}
.toClass()
方法 val task = launch { // long running job }
task.join()
task.abort()
job.stop()
task.cancel()
Long
分配给 Int
,反之亦然 Int
到 Long
没有隐式转换 Long
类型 望显示一条特殊消息。使用 Kotlin 范围,您应该添加哪些代码?
when (die) { 1 -> println("die is 1") 2 -> println("die is 2") ___ -> println("die is between 3 and 6") else -> println("die is unknown") }
3,4,5,6
in 3..6
3 : 6
{3,4,5,6}
instanceof
is
typeof
as
firstName?.let { println("Greeting $firstname!") }
firstName
等于 null
firstName
等于空字符串 firstName
等于布尔值 false
simple()
。您在该函数上添加了 inline
前缀。这对代码有什么影响?inline fun simple(x: Int): Int{
return x * x
}
fun main() {
for(count in 1..1000) {
simple(count)
}
}
for (_____) { println("There are $count butterflies.") }
count in 1..10
count in 2..10 step 2
count in 1..10 % 2
var count=2; count <= 10; count+=2
val set = setOf("apple", "pear", "orange", "apple") println(set.count())
println(b!!.length ?: 0)
println(b?.length ?: 0)
println(b?.length ?? 0)
println(b == null? 0: b.length)
removeBadValues
。在下面的代码行中,什么是调用 filter
中函数的正确方式?val list2 = (80..100).toList().filter(_____)
::removeBadValues
GlobalScope.removeBadValues()
Mainkt.removeBadValues
removeBadValues
for(z in 1..7) println("$z ")
for(z in 1..6) print("$z ")
for(z in 1 to 6) print("$z ")
for(z in 1..7) print("$z ")