2022-08-15
2126
#kotlin
Rahul Chhodde
127135
Aug 15, 2022 â‹… 7 min read

Initializing lazy and lateinit variables in Kotlin

Rahul Chhodde I'm a software developer with over seven years of experience in different web technologies.

Recent posts:

How To Use ForwardRef In React

React forwardRef explained: Usage, alternatives, and React 19 update

ForwardRef lets you pass refs through components to access child DOM nodes directly — learn how and when to use it in React 18 and earlier.

Peter Ekene Eze
Jun 3, 2025 â‹… 14 min read
Improving Frontend Workflows With In-Browser Database Tools

​​Improving frontend workflows with in-browser database tools

In-browser database tools like RxDB and Neo4j Sandbox help frontend devs manage data, work offline, and streamline tasks with AI support.

Jude Miracle
Jun 3, 2025 â‹… 7 min read
How To Iterate Over Enums In TypeScript

How to iterate over enums in TypeScript (with code examples)

Learn exactly how to iterate over numeric and string enums in TypeScript, with practical code snippets and type-safe patterns.

Matteo Di Pirro
Jun 2, 2025 â‹… 9 min read
How To Import SVGs Into Your Next.js Apps

How to import SVGs into your Next.js apps: A 2025 guide

Learn the best 2025 methods to import SVGs in Next.js 14+, with tips on performance, styling, and App Router integration.

Joseph Mawa
Jun 2, 2025 â‹… 9 min read
View all posts

One Reply to "Initializing <code>lazy</code> and <code>lateinit</code> variables in Kotlin"

  1. The `pi` example here is a bit misguided, because using `lazy` for that will consume more memory than just initialising the constant value.

    The one case where I would consider making `pi` lazy is if you are writing an arbitrary precision arithmetic library and have to calculate the value, because calculating the value can be very expensive if the caller asks for a large number of digits.

Leave a Reply