Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Kotlin Scope Functions are basically provided to manage the variable scopes easily. These are designed in a way that you can access the variables without even using their names again and again and also you don’t need to manage their scopes. You can definitely check the official doc.
Support, we have a class that has few variables in it.
As you can see above. If I want to access the variable from this class then I would have to create its object and use its identifier. The below-given code will help you with that.
As you can see we, again and again, writing the studentModel identifier to access each property.
Here the Kotlin Scope Functions come to rescue. Let’s see one by one each of them.
The object is represented by the argument (it). It returns the last statement of the lambda expression.
The object is available as a receiver (this). It returns the last statement of the lambda expression.
You can execute several statements with the run.
The object is available as a receiver (this). It returns the object itself.
The object is available as an argument (it). It returns the object itself.
And the main feature of all of these functions is that you don’t need to think about the object that has been created. The will be automatically destroyed as soon as the scope function completes.
That’s all for this blog. Thank you very much. This is Vedesh Kumar signing off.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.