kotlin試験toString,kotlin試tostring
分享于 点击 36922 次 点评:125
kotlin試験toString,kotlin試tostring
/*** The `is` operator checks if an expression is an instance of a type and more.
* If we is-checked an immutable local variable or property, there's no need
* to cast it explicitly to the is-checked type.
* See this pages for details:
* http://kotlinlang.org/docs/reference/classes.html#classes-and-inheritance
* http://kotlinlang.org/docs/reference/typecasts.html#smart-casts
*/
fun main(args: Array<String>) {
println(getStringLength("asdfTest"))
println(getStringLength(145623.toString()))
println(str)
}
fun getStringLength(obj: Any): Int? {
if (obj is String)
return obj.length // no cast to String is needed
return null
}
var num:Int = 1
var numStr:String = num.toString()
var str:String = "★★★★TEST■■■■" + num
相关文章
- 暂无相关文章
用户点评