1
1
Fork 0

Changed the task a bit to avoid having 'redundant initializer' IJ inspection

based on https://github.com/BruceEckel/AtomicKotlinExamples/issues/15
This commit is contained in:
Svetlana Isakova 2021-07-20 17:47:39 +02:00
parent 09aa533a41
commit 2573f12d1e
4 changed files with 9 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package varAndValExercise1
fun main() {
var answer = 42
println(answer)
answer = 43
println(answer)
}

View File

@ -4,7 +4,7 @@ files:
visible: true
placeholders:
- offset: 65
length: 47
length: 65
placeholder_text: // TODO
- name: test/output.txt
visible: false

View File

@ -1,5 +1,8 @@
## `var` & `val` (#1)
Define a `val answer` and set its value to `42`. On the next line, try to
reassign `answer` to `43`. What error does Kotlin produce? Fix the error by
replacing `val` with `var`. Display the value of `answer` on the console.
Define a `val answer` and set its value to `42`.
Display the value of `answer` on the console.
On the next line, try to reassign `answer` to `43`.
What error does Kotlin produce? Fix the error by replacing `val` with `var`.
Display the new value of `answer` on the console.