2020-11-17 22:00:10 +03:00
|
|
|
## Property Delegation (#2)
|
2020-09-27 01:27:15 +03:00
|
|
|
|
2020-11-17 21:48:49 +03:00
|
|
|
Start with:
|
|
|
|
|
|
|
|
```kotlin
|
|
|
|
class Delegator {
|
|
|
|
private var list = List(8) { "$it" }
|
|
|
|
var strings by list
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Define `getValue()` and `setValue()` as extension functions to `List<String>`
|
|
|
|
(Hint: IntelliJ IDEA will generate skeletons for you). The code in `main()`
|
2020-12-12 02:30:51 +03:00
|
|
|
tests your solution.
|
2020-11-17 21:48:49 +03:00
|
|
|
|
|
|
|
BONUS: Try adjusting `getValue()` and `setValue()` to work with:
|
|
|
|
|
|
|
|
```kotlin
|
|
|
|
class Delegator {
|
|
|
|
var strings by List(8) { "$it" }
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
And explain what happens.
|
2020-09-29 14:29:57 +03:00
|
|
|
|
2020-10-12 13:11:53 +03:00
|
|
|
<sub> This task doesn't contain automatic tests,
|
|
|
|
so it's always marked as "Correct" when you run "Check".
|
|
|
|
Please compare your solution with the one provided! </sub>
|