Symbols used in Scala Syntax

Scala Lang has many different symbols used in its syntax. Below is the list of symbols and their 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 the 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 a 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 separate 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 constrain the allowed types.
    def apply[T <: U](x:T)
  • “<%” symbol is called as view bound (apply implicit conversion) and is used in parameterized and abstract type declaration to convert the type using the view.
    def m[A<%B](args):R
  • “>:” symbol is 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)]
  • “#” symbol is used to refer to a type declaration nested in another type
    val ic: MyClass#myType
  • “@” sybmol marks an annotation
    @deprecated def sum() = ...

I hope these symbols used in Scala syntax helps you get started with Scala Programming language.