fun函数方法体=返回值,kotlin
var str: String = "fly"
fun main(args: Array<String>) {
println(getMyString())
println(getMyInt())
str = "phil"
println(getMyString())
println(getMyInt())
}
fun getMyInt(): Int {
return if (str.equals("fly")) {
1
} else if (str.equals("phil")) {
2
} else {
-1
}
}
fun getMyString() = str
fly
1
phil
2