Kotlin学习之操作符和特殊符号

一:数学操作符

 

+  -   *   /   %  这些是常见的数学操作符。表达相加,相减,相乘,相除,取余。

其中,*  在如下情况可以理解为 spread  传播操作符。

 

二:assignment operator(分配操作符)

 

=

        1,简单的变量赋值。接收函数的返回值。

        2,进行默认参数赋值

 

当调用函数的时候,不给参数。此时defaultValue() 进行默认参数赋值。

 

当函数都给了默认值的时候,我们在调用的时候,可以覆盖其默认值,但是参数名必须一致

 

此处在调用函数的时候,参数  b  未给默认值   所以  在调用的时候   必须显示声明并赋值

 

如果函数的参数是lambda,调用方式如上。

 

三:先进行操作,然后再赋值的操作符号

 

+=    -=   *=   /=   %=

 

四:自加,自减

 

++    --

 

五:基本逻辑操作符

 

&&  ||   !

 

六:逻辑操作符

 

==      !=

 

七:三等   

 

===   !==

 

==                是比较是否相等

===              是比较对象的地址是否相等

 

八:比较操作符

 

<             >                 <=                   >=

 

九:索引访问操作符

 

[ ]    比如   a [ i ]    表达的意思是:  a.get(i)

 

十:断言非空操作符

 

!!        比如   val a = b!!.length      如果b为    null    则抛出异常,如果  不为null   则取出值。  

 

十一:安全调用 操作符号

 

?.               

 

传统的思维方式,需要判断其是否为 null

aa?.length    表达变量  aa   如果为  null  直接打印 null  , 如果不为  null   则打印出来这个长度。

 

十二:Elvis  Operator

 

?:            

 

  

 

十三:member reference  or  class reference  or  function reference

 

::

 

 

十四: Rang  范围操作符

 

..

 

十五:separates a name from a type in declarations

 

                   val  a    :   Int? = 111

 

十六: marks a type as nullable

 

                  val  a:  Int ?  =  11

 

十七:                ->

       separates the parameters and body of a lambda expression

       separates the parameters and return type declaration in a function type

       separates the condition and body of a when expression branch

 

十八:                @

          introduces an annotation

          introduces or references a loop label

          introduces or references a lambda label

          references a 'this' expression from an outer scope

          references an outer superclass

 

十九:                  ;

 

         separates multiple statements on the same line

 

二十:                 $

 

      references a variable or expression in a string template

 

 

二十一:           -

            substitutes an unused parameter in a lambda expression

            substitutes an unused parameter in a destructuring declaration

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值