What are all the instances of syntactic sugar in Scala?

前端 未结 6 963
忘掉有多难
忘掉有多难 2020-11-30 17:10

What are all the instances of syntactic sugar in Scala?

They are hard to search for since most/all of them are purely symbols and are thus hard to search for without

6条回答
  •  一向
    一向 (楼主)
    2020-11-30 17:43

    Special Classes: Tuples and Symbols

    As mentioned by Rahul G, tuples and symbols get a slightly special syntax.

    • Symbols: the syntax 'x is short for Symbol("x")
    • Tuples: (p1,p2,..,pn) is short for a case class Tuplen[T1,T2,..,Tn](p1,p2,..,pn)

    For example, the following two are equivalent.

    val tuple1 = ("Hello",1)
    val tuple2 = Tuple2[String,Int]("Hello",1)
    

提交回复
热议问题