标签:scala symbol
scala主要分为Keywords/reserved symbols
即关键字符号 和 被保留的 符号
Keywords
// Keywords <- // Used on for-comprehensions, to separate pattern from generator => // Used for function types, function literals and import renaming
我们在前面的博客对<- 和 =>有所提及,这里在简单描述一下。
<- 用于for逻辑内部 如:
for (p <- range if p > 5) yield p
=> 有三个比较常见的地方
1. 导入中用到
// 1. import
import scala.{ Predef => _, _ } // 排除, 除了 Predef的其他所有类被导入2. for 逻辑内部用到
// 2. for args.foreach ( arg =>greeting += (arg + " ")) //for 章节中提到
3. match 逻辑内部用到
// 3. match case
var a = 1;
a match {
case 1 => 2 //a==1 则返回2
case 2 => 5
}Reserved
// Reserved
( ) // Delimit expressions and parameters
[ ] // Delimit type parameters
{ } // Delimit blocks
. // Method call and path separator
// /* */ // Comments
# // Used in type notations
: // Type ascription or context bounds
<: >: <% // Upper, lower and view bounds
" """ // Strings
‘ // Indicate symbols and characters
@ // Annotations and variable binding on pattern matching
` // Denote constant or enable arbitrary identifiers
, // Parameter separator
; // Statement separator
_* // vararg expansion
_ // Many different meanings译文:
被保留字
( ) // 定界表达式和参数
[ ] // 定界参数类型
{ } // 定界块
. // 方法调用或者 路径分离
// /* */ // 注释
# // 被用于type标记
: // Type 归属或者 上下文边界
<: >: <% // 大写 小写 以及视图边界 这个待定,这么翻译有点问题
" """ // 字符串
‘ // 标识符号以及字符
@ // 在正则表达式之上的注解和绑定
` // 表示常数或启用任意标识符
, // 参数分隔器
; // 语句分隔器
_* // 可变参数的扩展
_ // 不只有一个意思一个包括大部分符号的例子
package demo.scala
import scala._ //导入scala包下所有类
object symbolDemo {
def sdemo(x : Int) : String= {
var sl : List[Int] = List(1,2);
"" //字符串 当前函数的返回值
}
abstract class NativeType{
type JvmType
@transient val tag: List[JvmType]
}
}有多个含义的 -
import scala._ // Wild card -- all of Scala is imported
import scala.{ Predef => _, _ } // Exclusion, everything except Predef
def f[M[_]] // Higher kinded type parameter
def f(m: M[_]) // Existential type
_ + _ // Anonymous function placeholder parameter
m _ // Eta expansion of method into method value
m(_) // Partial function application
_ => 5 // Discarded parameter
case _ => // Wild card pattern -- matches anything
f(xs: _*) // Sequence xs is passed as multiple parameters to f(ys: T*)
case Seq(xs @ _*) // Identifier xs is bound to the whole matched sequence译文:
import scala._ // 通配符 导入所有的scala类
import scala.{ Predef => _, _ } // 导入除Predef的所有类
def f[M[_]] // Higher kinded type 的参数 (Higher kinded type 特有的一种类型)
def f(m: M[_]) // Existential type (一种类型)
_ + _ // 匿名函数的参数占位符
m _ // Eta expansion of method into method value
m(_) // 部分函数应用
_ => 5 // 丢弃参数
case _ => // 通配符
f(xs: _*) // 序列xs是传递多个参数到 f(ys: T*)
case Seq(xs @ _*) // 标识符的xs被绑定到整个匹配的序列
好吧,写这章让我有点痛苦,下一章继续更新
本文出自 “书生” 博客,请务必保留此出处http://yjplxq.blog.51cto.com/4081353/1412947
【scala初学】scala symbol 符号 -1,布布扣,bubuko.com
标签:scala symbol
原文地址:http://yjplxq.blog.51cto.com/4081353/1412947