From 458ca638345b79da755550ba5f204225927c11ce Mon Sep 17 00:00:00 2001 From: Yanis Ikene Date: Fri, 9 Sep 2016 15:13:00 -0400 Subject: [PATCH] class C(x: R) NOT same as class C(private val x: R) It says on the [cheatsheet](http://docs.scala-lang.org/cheatsheets/) that `class C(x: R) ` is the same as `class C(private val x: R)` which is not true. In this case (`class C(x: R) `), x is just a parameter that the constructor can receive and is only a local variable inside the constructor and not a member of the class. --- cheatsheets/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheatsheets/index.md b/cheatsheets/index.md index 6cbc9b512e..da4f15c2b9 100644 --- a/cheatsheets/index.md +++ b/cheatsheets/index.md @@ -66,7 +66,7 @@ languages: [ba, fr, ja, pt-br] | Good
`val v42 = 42`
`Some(3) match {`
`` case Some(`v42`) => println("42")``
`case _ => println("Not 42")`
`}` | "\`v42\`" with backticks is interpreted as the existing val `v42`, and "Not 42" is printed. | | Good
`val UppercaseVal = 42`
`Some(3) match {`
` case Some(UppercaseVal) => println("42")`
` case _ => println("Not 42")`
`}` | `UppercaseVal` is treated as an existing val, rather than a new pattern variable, because it starts with an uppercase letter. Thus, the value contained within `UppercaseVal` is checked against `3`, and "Not 42" is printed. | | object orientation | | -| `class C(x: R)` _same as_
`class C(private val x: R)`
`var c = new C(4)` | constructor params - private | +|
`class C(private val x: R)`
`var c = new C(4)` | constructor params - private | | `class C(val x: R)`
`var c = new C(4)`
`c.x` | constructor params - public | | `class C(var x: R) {`
`assert(x > 0, "positive please")`
`var y = x`
`val readonly = 5`
`private var secret = 1`
`def this = this(42)`
`}`|
constructor is class body
declare a public member
declare a gettable but not settable member
declare a private member
alternative constructor| | `new{ ... }` | anonymous class |