Using Constants Efficiently
Explore how to use constants efficiently in Kotlin by understanding the differences between companion objects and const val declarations. Learn how marking values as constants enables the compiler to inline them, improving code performance and reducing unnecessary object references. This lesson helps you write cleaner and more efficient Kotlin code.
We'll cover the following...
We'll cover the following...
Since everything in Java is an object (unless it’s a primitive type), we’re used to putting all the constants inside our objects as static members.
And since Kotlin has companion objects, we usually try putting them there: ...