设为首页 加入收藏

TOP

2. Scala变量(四)
2019-08-15 00:11:00 】 浏览:218
Tags:Scala 变量
号'....'包括的任意字符,即使是关键字(39个)也可以

object boke_demo01 {

  def main(args: Array[String]): Unit = {

    //首字符为操作符(比如+ - * / ),后续字符也需跟操作符 ,至少一个
    val ++ = "hello,world!"
    println(++)

    val -+*/ = 90 //ok
    println("res=" + -+*/)

    //看看编译器怎么处理这个问题
    // ++  => $plus$plus

    //val +q = "abc" //error

    //用反引号`....`包括的任意字符串,即使是关键字(39个)也可以

    var `true` = "hello,scala!"
    println("内容=" + `true`)

    val Int = 99.78
    println("Int=" + Int)

    //不能使用_ 做标识符
    //    var _ = "jack"
    //    println(_)
    
  }

}

  2.15.3 标识符举例说明 

hello //true
hello12  //true
1hello  //error
h-b  //error
x h  //error
h_4  //true
_ab  //true
Int  //true 在Scala中,Int不是关键字,而是预定义标识符,可以用,但是不推荐
Float  //true
_  //error 不可以,因为在Scala中,_有很多其它的作用,因此不能使用
Abc  //true
+*-  //true
+a  //error

  2.15.4 标识符命名注意事项  

      1) 包名:尽量采取有意义的包名,简短,有意义

      2) 变量名、函数名,方法名采用驼峰法

  2.15.5 Scala的关键字(39个)  

package, import, class, object, trait, extends, with, type, forSome 

private, protected, abstract, sealed, final, implicit, lazy, override 

try, catch, finally, throw

if, else, match, case, do, while, for, return, yield

def, val, var 

this, super 

new

true, false, null

 

     

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇2018-12-09 疑似bug_中文代码示例.. 下一篇6. Scala面向对象编程(基础部分)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目