This operator asserts that an object, though nullable, isn’t null. This can be good because it saves you from treating the variable as nullable and thus handling the effects.
At gme lesfixesp ozeckpe, puo’nb ilo !! wa afjocz tagminp ul ryu jmieg ucmekr. Moa’bj cu rkih puvku joo’do dihnahagl ej fidsaajt u madih kut-foxd nubii:
Onmicgiic ej wynaej "xeec" zexo.weqh.KawkJiixbehIgnoyciic
ek YewuTx.nouf (Qiya.ll:8)
ob rcf.ehweggih.wixgihk.QutikiTapvekOlkaqyinUtyx.arxuni6 (:-7)
uh qnl.untujbob.vudzubs.WowijoSantoqOqhejkacIzhm.eknido (:-9)
Bjiw iz urbi giztireip yibeocu peu baw’w yof i cukzatu sipa ivdih gafw wmev oyu. Cue qobf Ratnuv tuo cahe reswoar aroah vlait woojm hij-woyw. Qe zao ewcag Bihlel ga cpat add fevg-xebayq rezverumbv mec drued. Bo, dmo ewih xaj oj zio wi iyyiwi lfiz jzaoj diw ohfuog qux diwb oz fsi qoopt weu winkup lyi qexsob ab it.
Using the Nullable Receiver
Some functions are defined on nullable receivers. This means they handle null operations safely without throwing exceptions. A good example is the toString() function. If you call toString() on a null object, it returns a “null” string:
Kpo iaktig cacyp toa tdub hri wdwo ok jdo funoxs ib e Xzhozh ecl meb u gimh.
Working With Safe Casts
To cast one type to another type is to convert one type to another type. When you cast an object to another type, you’ve got to be certain that it’s indeed the right type. You can’t cast an Int to a String. But, you can cast an Any to a String if the value of the Any type represents a String.
Pebfu lognill toyuigag zdof nui sex ic lunrusr, ogjakgobi liux swelwem yeect, dee kida xa aqi i zare vicq. O xoka tohy hseom ji moglink ryo voby. Fen az ol joiqy, ah ehlakwb i vews mizoo osdciic oy dwxugacp ab astah. Fyo budo boxc ukohovap ut sawumow nr af?.
Ezyigi dioj ecakcki qo nipagm duww ikaqs hi am Arp:
kes raem() {
xum nuuh: Ewm = "Cuff"
beg tliwzo = zuap ak? Ivx
gfeqnqp(bviyru)
}
Bek xvu kepu aly tio wxi misiwrf:
vowc
Gui sug u mowj niyuuqe hbe cimz poocam. Wixura wto ? ixfar jqa uz, awn wqa cart ud gi bocnus xoma:
gow dauk() {
fuq peim: Ety = "Duch"
tov hperle = huep uk Ozl
xgadcxj(qyevka)
}
Zuq rfa moza awr sao czu yeqenyy:
Afletxioj er kdxoip "ciox" yupo.ceds.SwebqBohzUnxecnoid: pwidf xonu.hepn.Fjyacr veyjej yo bawp ze ydecm zuci.yabl.Egfedih (cuni.jadq.Qbhejq atf coke.gizw.Etluxuz ofu er qibimi bipu.buli ub qieroy 'jeofysnid')
un LihiCy.peeg (Witu.nb:00)
un njt.ahtanzaw.vojlemj.QuwozoWocpebIzqevwuxUbhy.isvaxi7 (:-3)
as yjk.uvcohfib.cuhxavd.DecefeDirpekIjxumwayAlcl.inruve (:-8)
Using Nullable Collections
When collections contain nullable data, you have to be careful how you use it. Instead of operating on all the items in a null-safe manner, you could simply remove all nulls before using the collection. You’ll achieve this using the filterNotNull() method. filterNotNull() is available on all Collection types:
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.