Home > Enterprise >  Kotlin - What does @Stable do?
Kotlin - What does @Stable do?

Time:03-09

I've been following this article and I'm unsure what the @Stable annotation does. I have seen this documentation but I need an example to better understand.

CodePudding user response:

@Stable is an Annotation that will tell the compiler that it's value will not change and return exactly the same value. This should only be applied to functions or values that are static the whole time.

The main reason why this is used is simple:

  1. Increased performance -> compiler will be faster because you tell him how to handle it.
  2. You can return always the same value, that can't be changed.
  • Related