gregd
07/21/2017, 1:19 PMkirillrakhman
07/21/2017, 1:20 PMkirillrakhman
07/21/2017, 1:20 PMgregd
07/21/2017, 1:22 PM::
will stay anyway?kirillrakhman
07/21/2017, 1:23 PMmzgreen
07/21/2017, 1:30 PMclass A {
var b = B()
}
class B {
var value = 5
}
let a: A? = A()
let foo = a?.b.value // I don't have to put ? after b and whole expression has Int type
In Kotlin I would have to do val foo = a?.b?.value
and the whole expression would be an Int?
. Is any of these approaches better? And why if so?dalexander
07/21/2017, 1:33 PMmzgreen
07/21/2017, 1:40 PMlet foo: Int = a?.b.value
then it shows an error which makes sense, but if I let it infer the type then it works and if I set a
to nil
then foo
is null which would suggest that it’s actually an Int?
but IDE shows me Int
.
I guess it’s an IDE bug.
let a: A? = A()
let foo = a?.b.value
foo is Int // prints true for Int and for Int?
but
let a: A? = nil
let foo = a?.b.value
foo is Int? // prints true only for Int?
mzgreen
07/21/2017, 1:42 PMdalexander
07/21/2017, 1:42 PM?.
short circuit when the value is null (C#), which makes variable assignment awkward (as well as some other things). If you do variable assignment then you want ?.
to return null so afterwards, which is why Kotlin handles it the way it does. I wasn’t sure which way Swift handled it which is why I asked.mzgreen
07/21/2017, 1:44 PMjackmiras
07/21/2017, 3:34 PMquantez
07/21/2017, 5:10 PMRuckus
07/21/2017, 5:13 PMCtrl + Alt + L
gives me 🙂kevinmost
07/21/2017, 5:43 PMkevinmost
07/21/2017, 5:43 PMkevinmost
07/21/2017, 5:43 PMjw
07/21/2017, 7:31 PMdiesieben07
07/21/2017, 7:32 PMansari
07/21/2017, 7:32 PMagentk
07/21/2017, 11:48 PMrogeralsing
07/22/2017, 6:16 AMmohita
07/22/2017, 7:14 AMmohita
07/22/2017, 7:15 AMmohita
07/22/2017, 7:15 AMmohita
07/22/2017, 7:15 AMmohita
07/22/2017, 7:16 AModay
07/22/2017, 7:17 AModay
07/22/2017, 7:18 AMp
fromrogeralsing
07/22/2017, 7:51 AM