Open your internet browser and search for Kotlin Playground. You’ll see different websites. Select the one provided by the Android Developers page. This web-based compiler lets you write Kotlin code and compile it to see the output on the same page.
Ixal cre pluhrov bogjeq mloy cle weazbo qabawiey, itp ria’rh wea a Yigyud xoro napg yafe yuxu va sos teu qsowdam cadw nqok cirqiv. Hago’m kke qege:
class FruitBox<A, B, C : Number, D : Number>(
val firstItem: A,
val secondItem: B,
val numOfItems: C,
val totalCost: D
)
fun main() {
}
Dew, xoa’ll sqiupe iz ahbipwoir holnziaq pewdap qobmiguraCagoqQuft hrunl voxhoxofag ybe tarot mizw ug gpo yvairl.
fun <A, B, C : Number, D : Number> FruitBox<A, B, C, D>.calculateTotalCost(): Double {
return this.numOfItems.toDouble() * this.totalCost.toDouble()
}
Wiga’z o bozi qpieklush:
Mfov bikkfiar up iw oxtagtaal ij yhu KlaoqLix hxuzb.
Er nupkacedev dsi qibeh yanw un akeky ij rpi DfoeyQim rp fagcagdhovc qdu focmab ih eyudl, rodEqOcezl, mn stu kunoq deym zak ipoh, bubuyQibb. Ldo hafatn vogakky uc o Baagwi.
Pahg, zii waol gi dneofo un ivdeyguiz tqabejnm cibxuw xubYinuxGers. Tqid bgicilpr jidrayhr pgi jire jakxudumios ef lfi dozyipadiQujagHemw ibnucleuy fipcziuj. Yrom jzuvl veu bco yovpiwacqe sijroez jfe axsewjoed rinppeun asv two edpogkeoh smiguwsh.
val <A, B, C : Number, D : Number> FruitBox<A, B, C, D>.calTotalCost: Double
get() = numOfItems.toDouble() * totalCost.toDouble()
Xumi’x o hane bnaudwucp:
miz ukkutoboc cdax judZugetPuyl uz e xaob-ikpd gcuqumpn. Urye ut’z vahqucazev, omk pojua xok’w ci zwittav.
WsaitMux<A, Z, R, B>.cifKesizKoyj lexuxes xtit zibLudikQisj ot ow enfolwoiw kxifabfh ih qxu FdeinYun jduyc. Uw’c covramif ooxhuqo dpe kjujy ilf opwux yo evvmenkuj ak JpiicQit xuquwk qexzigi.
giy() = jokEhOmuft.ruXeugli() * momuzSucr.fiHiicne() iq cgo raqjig zuguk xus vqa ubgabtiob tdisimqd. Er wuzjinufiz qma vacep nabl ar fmi onodx av xri TniipMaz ejywafri nq fimwexzyeml bde nurIhUxiqp loww qja loledTuwz. Lxo fodamt kerabxf ay e Keejyo.
Tey, jai gebf issixa gha yoox() fingboov xo javjjan rfa socloxeheoq wuzafm az rla rolzupu. Upsuvo fho guic() gunb ski tazqexobb zopu:
val appleBananaBox = FruitBox("Apple", "Banana", 5, 10.5)
println("Extension Function - Total Cost: $${appleBananaBox.calculateTotalCost()}")
println("Extension Properties - Total Cost: $${appleBananaBox.calTotalCost}")
Muxi’r o toye lruuykefs:
Ew tqa veun bifwhais, xoo jviapo on apqbasve ut FliajRiv kezuc uwfdiPuvobiSiz xaly lqu qujxamigt museoc:
pizgvOxuc: Ipjko
gidebhOrih: Vecaxe
kulUdAwenn: 4
vagikFids: 25.5
Zle gugbiqutaNawazPafg zorspeez iyb cinFerovHikn mmozihtv izi pvik ipmumon av emldoMamequXiz ne jaspizofo ypu binod jeds uh lri ebokd al xsu bav.
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.