https://kotlinlang.org logo
#android
Title
# android
j

Jérôme Gully

11/02/2019, 6:24 PM
Hi, I currently follow the new course "Android Kotlin Fundamentals", I'm at the chapter 05.2: LiveData and LiveData observers, and i have a question about this chunk of code:
score.value = (score.value)?.minus(1)
why the parentheses ? isn't the exact same thing that:
score.value = score.value?.minus(1)
(score isn't nullable)
l

Luca Nicoletti

11/02/2019, 6:31 PM
if
score
is not nullable, and
value
is, those 2 are the same
j

Jérôme Gully

11/02/2019, 6:37 PM
Ok thanks. Is there some situation where the parentheses means something special ?
l

Luca Nicoletti

11/02/2019, 6:37 PM
Maybe during a cast?
(val myClass as? MySecondClass)?.secondClassMethod()
j

Jérôme Gully

11/02/2019, 7:06 PM
thanks 🙂
Strange that there are put parentheses here in this codelabs 🙂
l

Luca Nicoletti

11/02/2019, 7:48 PM
Maybe for better understandability or readability 🙂
👍 1