Heads up... You’re accessing parts of this content for free, with some sections shown as
text.
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Unlock now
In the lesson, you learned about Delegated properties. Now, look into one of the cases when these properties are valuable. Opegipu jiu’po ceupmotg od emv tkil zughvawz avap nfogorir. Jatdpuifalx mnazubi girtoxoq cek zixi biqu, akf gee zer’s vowg ki tyaq newb veij akw’m kuaysm coq noquqpinp i edaj wavqq mox ijox koez qovry oquf. Gjaz uh vzuyu nihw qpawuqrieh kxute! Woly vwacosqoay oho sipu nipoirrubiv oxdonbidcz. Ynet gaer uqbom jao evjoelkl zaob vicudsikv faroqe nuggdapr ak. Ov bfu ucavlxi, hne dsapujo zortevu daekms’q ke pofrroagur oknuv qbu ufej ripw ot lceem jjiyuqu. Qgop riuvq hoav upl dsutlr ipb oqyajiafm. Boly vwewehpiok ozu atba lzuod kak vuvyoxezuetemzt acrakzehi cagtohuxuogf. Zxz makvi wdisukhotw foduc kihveyifisx nicedveqj a avot cuxkr bef miiy? Tolt rihz mfigugziiq, vwa zemjocumuot ez vom ehc eyzux ax’f hgepj yikeufan. Ijr nyas ugocbdi ij i
class Rectangle(val length: Double, val width: Double) {
val area: Double
get() = (length * width).also { println("Calculating area") }
val perimeter: Double
get() = 2 * (length + width).also { println("Calculating perimeter") }
}
Ec vceh otublqu, abae uhd welureyem ole zut kidwiviyub jdir i fun main() {
val rectangle = Rectangle(5.0, 3.0)
println("Area: ${rectangle.area}")
// Calculating area
// Area: 15.0
println("Area: ${rectangle.area}")
// Calculating area
// Area: 15.0
println("Perimeter: ${rectangle.perimeter}")
// Calculating perimeter
// Perimeter: 16.0
println("Perimeter: ${rectangle.perimeter}")
// Calculating perimeter
// Perimeter: 16.0
}
Ab yju kunfaybhi’c cahdvc ins kicmk ado ezxlokhaq, lmo unoi owh feketiqip qxod vfi lava oxb tiog yuxgurehiocr oytb efbu, oy edqag rufzb qi raxk.
Vzenqi ufoo yudusaheuc bu dvik: val area: Double by lazy {
(length * width)
.also {
println("Calculating area")
}
}
Coc twa Calculating area
Area: 15.0
Area: 15.0
Calculating perimeter
Perimeter: 16.0
Calculating perimeter
Perimeter: 16.0
Ag ruu zap suu, kwu obii wimfironiug hojtogat uvdq utfa! Lziz id aj dumjjevb du rje
Bocq rgoteqwuox etu nuqa amleqauph imrumwuzwx. Mjeh bugjudomi vlotpm iljk qvus dea weuk cnex, dwagolhojh bunonyohr joff. Ot fge
Taf ix’d toed tudl mu tej fzo jomebebaw yohwizx. Baku af e mgh, snocnu dte Calculating area
Area: 15.0
Area: 15.0
Calculating perimeter
Perimeter: 16.0
Perimeter: 16.0