Kotlin基础语法(一)
一、基本语法
1. 表达式的使用
//1、函数声明,可用表达式,自动推断返回类型之类的
fun sum(a:Int,b:Int):Int{
return a + b
}
//改为表达式,并自动推断返回类型
fun sum(a:Int,b:Int) = a+b
//2、结合条件判断的表达式
fun max(a:Int,b:Int):Int{
if(a>b){
return a
}else{
return b
}
}
//可简写为
fun max(a:Int,b...
原创
2020-12-31 09:46:41 ·
237 阅读 ·
0 评论