Scala 太 sao 啦,在学习关键字的时候就感受到了!
Scala 关键字
下表列出了 scala 保留关键字,我们不能使用以下关键字作为变量:
| abstract | case | catch | class |
| def | do | else | extends |
| false | final | finally | for |
| forSome | if | implicit | import |
| lazy | match | new | null |
| object | override | package | private |
| protected | return | sealed | super |
| this | throw | trait | try |
| true | type | val | var |
| while | with | yield | (空格) |
| - | : | = | => |
| <- | <: | <% | >: |
| # | @ |
关键字解读
forSome
用在已存在的类型声明中,限制其能够使用的具体类型。
scala> def foo(x : Array[T] forSome { type T <: CharSequence}) = x.foreach(y => println(y.length))
foo: (Array[T] forSome { type T <: java.lang.CharSequence })Unit
implicit
implicit adj. 含蓄的;暗示的;盲从的
用于支持 scala 中的隐式转换功能,包括隐式参数赋值,隐式类型转换,隐式方法声明,可以减少编码量,但会降低代码可读性。
或曰:使得方法或变量值可以被用于隐含转换;将方法参数标记为可选的,只要在调用该方法时,作用域内有类型匹配的候选对象,就会使用该对象作为参数。
详情参考:https://www.cnblogs.com/MOBIN/p/5351900.html
lazy
var 和 val
:> 和 :<
描述不同类型之间的继承关系。
[B >: A]is a lower type bound. It means thatBis constrained to be a supertype ofA.Similarly
[B <: A]is an upper type bound, meaning thatBis constrained to be a subtype ofA
参考:
Scala Reference, last access 2019-01-02, https://www.scala-lang.org/docu/files/ScalaReference.pdf
本文介绍了Scala编程语言中的保留字,特别是`forSome`、`implicit`和`lazy`的关键字解读。`forSome`用于限制类型声明,`implicit`支持隐式转换和参数赋值,`lazy`关键字实现延迟初始化。此外,还提到了类型边界`:>`和`:<`的概念。
1090

被折叠的 条评论
为什么被折叠?



