美文网首页
习惯用法

习惯用法

作者: yesyourhighness | 来源:发表于2019-06-04 14:56 被阅读0次

函数的默认参数
过滤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()
}

相关文章

网友评论

      本文标题:习惯用法

      本文链接:https://www.haomeiwen.com/subject/tvqhxctx.html