您当前的位置: 首页 >  kotlin

蓝不蓝编程

暂无认证

  • 0浏览

    0关注

    706博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Kotlin中如何区分基础类型和包装类型

蓝不蓝编程 发布时间:2019-01-15 17:29:00 ,浏览量:0

背景:

Kotlin没有区分基础类型和包装类型,而是通过初始值是否为null来区分的。如果为null,则是包装类型,否则是基础类型。

详细对照关系如下:

 java写法kotlin写法 java写法kotlin写法基础类型byte byteValue;var byteValue: Byte = 0包装类型Byte byteValue;val byteValue: Byte? = nullshort shortValue;var shortValue: Short = 0Short shortValue;val shortValue: Short? = nullint intValue;var intValue: Int = 0Integer intValue;val intValue: Int? = nulllong longValue;var longValue: Long = 0Long longValue;val longValue: Long? = nullfloat floatValue;var floatValue: Float = 0.toFloat()Float floatValue;val floatValue: Float? = nulldouble doubleValue;var doubleValue: Double = 0.toDouble()Double doubleValue;val doubleValue: Double? = nullchar charValue;var charValue: Char = ' 'Character charValue;val charValue: Char? = nullboolean booleanValue;var booleanValue: Boolean = falseBoolean booleanValue;val booleanValue: Boolean? = null

Kotlin反编译代码对照:

 

 

安卓开发技术分享: https://blog.csdn.net/yinxing2008/article/details/84555061

 

 

关注
打赏
1639405877
查看更多评论
立即登录/注册

微信扫码登录

0.0369s