Symbols used in Syntax of Scala Language

Scala Lang has many different symbols used in its syntax. Below is the list of symbols and its use in Scala language.

  • “->” arrow symbol in Scala syntax returns a two element tuple containing the key and value. You can use this symbol as shown in below example-
     Map(1->"Allan", 2->"Bob") (1).->("A) 
  • “_” underscore symbol  in scala syntax is intended as a place holder, used in imports, functions literals.
     import com.kodehelp.scala._ case_=> value.toString 
  • “:” colon symbol in scala syntax act as separator between identifiers and type annotations.
     def add(i:int):Int= ... 
  • “=” equal symbol in scala act as assignment operator
     val ten = 10 
  • “=>” symbol is used in function literals to seperate the argument list from the function body
    numbers.filter(x => x)
  • “<-” symbol is used for comprehensions in generator expressions
    for(obj <- objects)
  • “<:” symbol is called as Upper bound (a subtype of) and is used in parameterized and abstract type declaration to contrain the allowed types.
    def apply[T <: U](x:T)
  • “<%” symbolis called as view bound (apply implicit conversion) and is used in paramaterized and abstract type declaration to convert the type using view.
    def m[A<%B](args):R
  • “>:” symbolis called lower bound (super type of) and is used in parameterized and abstract type declarations to constrain the allowed types.
    def append[U >:T(x:U)]
  • “#” symbolis used to refer to a type declaration nested in another type
    val ic: MyClass#myType
  • “@” sybmolmarks an annotation
    @deprecated def sum() = ...

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *