您当前的位置: 首页 >  ar

ZhangJiQun&MXP

暂无认证

  • 0浏览

    0关注

    1187博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

kotlin 学习,val和var的区别

ZhangJiQun&MXP 发布时间:2020-02-25 23:45:24 ,浏览量:0

学习:

https://www.runoob.com/kotlin/kotlin-tutorial.html

https://www.jianshu.com/p/f9e78d6c54bd

练习:

https://www.runoob.com/try/runcode.php?filename=hello&type=kotlin

https://try.kotlinlang.org/#/Examples/Hello,%20world!/Simplest%20version/Simplest%20version.kt       这个好用

 

var是一个可变变量,这是一个可以通过重新分配来更改为另一个值的变量。这种声明变量的方式和Java中声明变量的方式一样。 具体使用

val是一个只读变量,这种声明变量的方式相当于java中的final变量。一个val创建的时候必须初始化,因为以后不能被改变。

 

sample:

/**
 * We declare a package-level function main which returns Unit and takes
 * an Array of strings as a parameter. Note that semicolons are optional.
 */

package hello                      //  可选的包头
 


class DB(){
fun get(){
		println("aa")

}}
fun sum(a:Int,b:Int): Int{
    return a*b
}
fun sum2(a:Int,b:Int): Int=a+b
fun main(args: Array)
{
    val aa=sum(2,3)
    println(aa)
        println(sum2(2,4))

}

 

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

微信扫码登录

0.0442s