Kotlin于Android Studio写Android应用(二)
说一下一些基本的kotlin概念,之后才开始说 kotlin 的android 开发 (以下会有一些android API的语法,很少量的...)
还有,Kotlin不用new,别问我new到哪去了...
基本编
1. 所有object预设的visibility为public,有需要请自行宣告(除了static)
http://paste.ofcode.org/ssVC5XhymavPTz3dhh22Ec
2. 宣告方法用fun,宣告变数用var,宣告常数用val
http://paste.ofcode.org/hmhCQUJtZ695KbeM4Er8Bj
3. type cast用as
http://paste.ofcode.org/ywtiyEgrM9X3AvnmVUG3yk
4. 类型空安全
http://paste.ofcode.org/XcCXZpmVZsdkEFFW3RTMyb
5. static已经不存在了,请用object(class)/companion object(inner class)
http://paste.ofcode.org/YPrjSMsmU9nqirnTjn8StU
6. 条件判断式(一) if-else与?:
http://paste.ofcode.org/J7FNqj6EksgmAwNd5nWycb
7. 条件判断式(二) when
http://paste.ofcode.org/gy4KJ9x34RVtdFVqwRHtdz
这个我觉得不用加注解了...
8. 回圈(一) for
http://paste.ofcode.org/QGShD5Kxf7czNi3KPHxh25
9. 回圈(二) for with key and value
http://paste.ofcode.org/32inA9La4MTgjfsuWvtENrw
10. 回圈(三) while与do-while
与Java的一样
11. 取代instanceof 的 is
http://paste.ofcode.org/uDjfPmeg7QgbrKWUdAVD63
进阶编
1. Lambda Expression
http://paste.ofcode.org/PXYY3X3gAtRkhVYs4Wg3DV