Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
Difference between lazy{} vs getter() initialization in kotlin

In kotlin we can use both of these approach lazy{} and getter()

lazy initializaiton:

internal val connector by lazy {
        serviceConnector
    }

getter():

internal val connector : ServiceConnector
        get() = serviceConnector

When to use which approach and what actually does these two approach under the hood. Which one is best approach?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When you use the lazy delegate, the val is initialized only when you use it the first time. So, in your code, the first time you access connector, the code inside the lambda is run, and the result is assigned to the val.

get(), instead, is used to redefine what happens when you try to access the val.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!