Kotlinで初め
来源:互联网 发布:淘宝女士太阳镜 编辑:程序博客网 时间:2024/05/22 14:46
/**
* 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()))
}
fun getStringLength(obj: Any): Int? {
if (obj is String)
return obj.length // no cast to String is needed
return null
}
* 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()))
}
fun getStringLength(obj: Any): Int? {
if (obj is String)
return obj.length // no cast to String is needed
return null
}
阅读全文
0 0
- Kotlinで初め
- Kotlin的初窥之kotlin配置
- kotlin初窥之Kotlin Android Extensions
- Kotlin初体验
- Kotlin初体验
- Android Kotlin初体验
- Kotlin初体验
- Kotlin初体验
- Kotlin 初运行
- Android Kotlin 初体验
- kotlin初接触
- Kotlin 入门初体验
- Android Kotlin初体验
- Kotlin初体验
- Android Kotlin初体验
- Kotlin初体验
- kotlin初体验
- Kotlin
- Winfrom控件之DataGridView
- Android如何判断NavigationBar是否显示(获取屏幕真实的高度)
- 金融商品与普通实物商品的区别
- 洛谷【p1122】最大子树和
- Swing中Timer定时器的作用
- Kotlinで初め
- JQuery——Ajax之XMLHTTPRequest对象
- android 友盟QQ分享
- java mysql 高性能批量处理 设置rewriteBatchedStatements
- Java byte数组转16进制字符串
- elasticsearch的准实时(near real-time)查询
- mouseover mouseout mouseenter mouseleave解释
- 很抱歉 程序无法在非mbr引导的分区上激活
- JSP 界面sql语句执行