diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-03-12 16:37:05 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-03-12 16:37:05 -0700 |
commit | f0b37c2f8f7ba865c8fedda4bf6b47192d9e2ebf (patch) | |
tree | 8889631a82926f2b5bd13dd75bd8476803f781d3 /06-basic-declarations-and-definitions.md | |
parent | 5135bae5a7c2d156dd55dfc0aabf8b41d393f4a2 (diff) | |
download | scala-f0b37c2f8f7ba865c8fedda4bf6b47192d9e2ebf.tar.gz scala-f0b37c2f8f7ba865c8fedda4bf6b47192d9e2ebf.tar.bz2 scala-f0b37c2f8f7ba865c8fedda4bf6b47192d9e2ebf.zip |
SI-1972 clarify getter and setter must be declared together
Diffstat (limited to '06-basic-declarations-and-definitions.md')
-rw-r--r-- | 06-basic-declarations-and-definitions.md | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/06-basic-declarations-and-definitions.md b/06-basic-declarations-and-definitions.md index b8eb226d3d..8abe68c137 100644 --- a/06-basic-declarations-and-definitions.md +++ b/06-basic-declarations-and-definitions.md @@ -202,18 +202,16 @@ VarDef ::= PatDef | ids ‘:’ Type ‘=’ ‘_’ ``` -A variable declaration `var $x$: $T$` is equivalent to declarations -of a _getter function_ $x$ and a _setter function_ -`$x$_=`, defined as follows: +A variable declaration `var $x$: $T$` is equivalent to the declarations +of both a _getter function_ $x$ *and* a _setter function_ `$x$_=`: ``` def $x$: $T$ def $x$_= ($y$: $T$): Unit ``` -An implementation of a class containing variable declarations -may define these variables using variable definitions, or it may -define setter and getter functions directly. +An implementation of a class may _define_ a declared variable +using a variable definition, or by defining the corresponding setter and getter methods. A variable definition `var $x$: $T$ = $e$` introduces a mutable variable with type $T$ and initial value as given by the @@ -231,20 +229,20 @@ the free names in $p$ are introduced as mutable variables, not values. The name of any declared or defined variable may not end in `_=`. -A variable definition `var $x$: $T$ = _` can appear only -as a member of a template. It introduces a mutable field with type -\ $T$ and a default initial value. The default value depends on the -type $T$ as follows: - ----------- -------------------------------------------------- -`0` if $T$ is `Int` or one of its subrange types -`0L` if $T$ is `Long` -`0.0f` if $T$ is `Float` -`0.0d` if $T$ is `Double` -`false` if $T$ is `Boolean` -`()` if $T$ is `Unit` -`null` for all other types $T$ ----------- -------------------------------------------------- +A variable definition `var $x$: $T$ = _` can appear only as a member of a template. +It introduces a mutable field with type $T$ and a default initial value. +The default value depends on the type $T$ as follows: + +| default | type $T$ | +|----------|------------------------------------| +|`0` | `Int` or one of its subrange types | +|`0L` | `Long` | +|`0.0f` | `Float` | +|`0.0d` | `Double` | +|`false` | `Boolean` | +|`()` | `Unit` | +|`null` | all other types | + When they occur as members of a template, both forms of variable definition also introduce a getter function $x$ which returns the |