Kotlin lazy delegate - explanation and example

Поділитися
Вставка
  • Опубліковано 6 жов 2024
  • Lazy is an inbuilt Kotlin function which allows us to construct the object when it's actually used, and subsequent calls return the remembered result.
    ➤ Docs: kotlinlang.org...
    ➤ lazy vs lateinit: / kotlin-variable-to-be-...
    ➤ Programming Kotlin by Venkat Subramaniam: amzn.to/33yHJ7r
    ➤ Android Cookbook: amzn.to/3IfEX6h
    ➤ Head First Kotlin: amzn.to/3I77Z7Z
    Hi! I’m Rahul, a software engineer with a passion for teaching. I went to Stanford, was a founding engineer at a startup, and have worked at various companies across Silicon Valley. I’m currently an Android Developer at Facebook and teach an Android class at Stanford. Would love to connect with you! This channel is about tech (especially Silicon Valley), combining tactical how-to guides with interviews.
    📹 UA-cam: www.youtube.co...
    📝 LinkedIn: / rpandey1234
    🐦 Twitter: / rpandey1234
    📸 Instagram: / rpandey1234
    📂 Github: github.com/rpa...

КОМЕНТАРІ • 64

  • @RahulPandeyrkp
    @RahulPandeyrkp  3 роки тому +5

    Learn Kotlin in 12 Minutes: ua-cam.com/video/iYrgWO2oibY/v-deo.html

  • @jokersmith9096
    @jokersmith9096 3 роки тому +8

    I just wanted to say thank you, this is incredible content.

  • @scottbiggs8894
    @scottbiggs8894 4 місяці тому

    Thanks for the deeper dive into the lazy code.

  • @tejaspatel7170
    @tejaspatel7170 Рік тому

    Amazing and awesome. seen someone today who dive into source and explain things at peak... HAPPY TO SEE THIS EVEN IN 2023 !

  • @Dinesh-vg3sg
    @Dinesh-vg3sg 6 місяців тому

    Thanks sir, I liked the way you have explained things in detail.

  • @kartikayy
    @kartikayy 2 роки тому

    While we can implemented own version of lazy initialization, lazy in kotlin still saves a lot of boiler plate code. Thanks for the video.

  • @jam4l
    @jam4l Рік тому

    OMG this is amazing, the way you have explained just wow, TY.

  • @siddharthchughs100
    @siddharthchughs100 2 роки тому

    Hi Rahul , I really appreciate your knowledge and your insight on topics, which is quite very good, Thanks again.

  • @vengateshm2122
    @vengateshm2122 3 роки тому +1

    Nicely explained with internal working.

  • @onmoveonmove226
    @onmoveonmove226 Рік тому

    Thank you for your explanation

  • @komodotanjidor7272
    @komodotanjidor7272 2 роки тому

    Great simple explanation but nonetheless clear as crystal

  • @ashishgautam2842
    @ashishgautam2842 3 роки тому +1

    You are polishing us 🙏🙏

  • @BelhouchetInesyen
    @BelhouchetInesyen 3 роки тому +1

    Great quality, very efficient.

  • @shubhamnanche
    @shubhamnanche Рік тому

    Great explanation 😃

  • @ananjaygurjar
    @ananjaygurjar 2 роки тому

    Incredible way to explain stuff!!

  • @telurasinmontasik2406
    @telurasinmontasik2406 Рік тому

    this is what I need

  • @shutanovac
    @shutanovac 3 роки тому +1

    This helped me understand the lazy delegate :-) Thanks man! Can you also talk about other delegates?

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому +1

      thank you! will definitely consider other delegates :)

  • @rajeetgoyal6879
    @rajeetgoyal6879 3 роки тому +2

    Great content🔥 Please consider making your videos in Dracula theme. That might be a lot more pleasing for eyes :)

  • @Another0neTime
    @Another0neTime 3 роки тому +1

    Great explanation!

  • @nalinitippa5942
    @nalinitippa5942 3 роки тому

    Great instruction !!

  • @BehnamKhani
    @BehnamKhani 2 роки тому

    great!

  • @emanalsbeiheen5619
    @emanalsbeiheen5619 3 роки тому

    Thank you Rahul very helpful content 🌹.. Can you please talk about Refliction in kotlin and how to use it please...

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому +1

      Sure, can add reflection to my list. I don't use it too frequently though

  • @nathann4291
    @nathann4291 3 роки тому

    THE LEGEND

  • @droidcasts7350
    @droidcasts7350 3 роки тому

    nice explanation, thank you

  • @matt-g-recovers
    @matt-g-recovers Рік тому

    Subbed

  • @house_d2024
    @house_d2024 3 роки тому

    hello Rahul , i like the way you teach! I want to ask you two things : to teach us kotlin multiplaform and to create a project using sqlite in android . THANK YOU A LOT

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому +1

      thanks a lot! I'd also like to do something on SQLite!

  • @-no-handle
    @-no-handle 3 роки тому +2

    Feels like I found a Gold mine.

  • @ravi_sorathiya
    @ravi_sorathiya 3 роки тому

    Thanks coding in flow

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому +1

      thank you + coding in flow

    • @ravi_sorathiya
      @ravi_sorathiya 3 роки тому +1

      @@RahulPandeyrkplooking forward to in depth kotlin corotines and flow tutorial
      If you planning to make it

    • @ravi_sorathiya
      @ravi_sorathiya 3 роки тому

      I just hit that subscribe button without wasting any further time after coding in flow posted insta story
      Know that's something is awesome there

  • @MisterWealth
    @MisterWealth 2 роки тому

    Does anyone have a realistic example of a late init?

  • @SuboptimalEng
    @SuboptimalEng 3 роки тому +4

    Good thing I’m lazy AF

  • @fernandoperalta891
    @fernandoperalta891 3 роки тому +1

    Hi Rahul, I really enjoyed this video! I had a question about your 'My Memory Game' tutorial on the freeCodeCamp channel. I wanted to ask if if would be ok to edit a couple of features from the tutorial version and then publish it for myself on the Google Play Store. I'm fairly new to licensing and using open source software so I wanted to ask if this would be ok instead of doing it without asking. I hope you can get back to me and I love your videos!!!

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому +2

      Thanks Fernando! I also replied on LinkedIn, copying over my message here in case it's helpful for others:
      You are welcome to take the tutorial + source code and do anything you want with it. You are free to add features, publish the app, or even commercialize it (a few people have done this). The open source license I used is Apache-2.0 License, which is quite permissive.

    • @fernandoperalta891
      @fernandoperalta891 3 роки тому

      Thank you for the clarification! I really appreciate it.

  • @gdnk703
    @gdnk703 3 роки тому

    Why automatic subtitles are not in english. Сan you fix it? Please

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому

      You should be able to control that on your end

  • @erenizci4197
    @erenizci4197 Рік тому

    Really good content but i am too lazy to implement this.

  • @avirias
    @avirias 3 роки тому

    Why lazy function definition has "actual" keyboard?, What is actual in kotlin ? 4:30

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому +2

      Great question - "actual" means the implementation of this function has a platform-specific implementation. Kotlin code can be used in multiple platforms, such as JavaScript environments, native code, or JVM-based environments as being done here (that's why this file is called "LazyJVM.kt").

  • @AS-iv6vx
    @AS-iv6vx 3 роки тому

    Why you add accountantDelegate? why not accountant.isInitialized()?

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому

      isInitialized doesn't exist as a method on the accountant, it's on the Lazy interface

    • @AS-iv6vx
      @AS-iv6vx 3 роки тому +1

      @@RahulPandeyrkp I understand, you have changed "by lazy {}" to "= lazy{}"

    • @RahulPandeyrkp
      @RahulPandeyrkp  3 роки тому +1

      @@AS-iv6vx yep exactly

  • @theai2020
    @theai2020 3 роки тому

    half of the video is just nothing just this and that try to squeeze things in more compact way but still informative