习惯用法

函数的默认参数
过滤list val = positives = list.filter{ it > 0}
字符串内插 println("name $name")
类型判断 when(x){
单表达式函数
对一个对象实例调用多个方法
class Turtle {
fun penDown()
fun penUp()
fun turn(degrees: Double)
fun forward(pixels: Double)
}
val turtle = Turtle()
with(myTurtle){
penDown()
for(i in 1..4){
forward(100.0)
turn(90.0)
}
penUp()
}

猜你喜欢

转载自blog.csdn.net/weixin_34174105/article/details/90921378