These two are equivalent, correct? (I know they co...
# getting-started
f
These two are equivalent, correct? (I know they could be inlined in the constructor) Edit: Forgot to remove the first two assignments in the 2nd snippet, just think that away
👌 1
s
You initialize name twice in the second
f
Oops forgot to remove that
e
Yes, the code snippets are the same, effectivey. As is
class User(val name: String, val age: Int)
j
As @eekboom said, they are effectively the same, but with Kotlin they are unnecessary, simply having them as constructor arguments will achieve the same:
Copy code
class User(val name: String, var age: Int)
or even better, have it as a `data class`:
Copy code
data class User(val name: String, var age: Int)
f
thank you