Learning Kotlin: ‘Const’ Modifier

Kotlin’s ‘const’ modifier allows you to mark a variable as a true, JVM compile-time constant.

To do this, the variable must meet several requirements.

  • 1. Must be a top-level variable or a variable on an Object
  • 2. Must be a String or primitive type
  • 3. No custom getter
  • 0:30 Example case study
  • 1:18 Examine bytecode
  • 1:26 Understand what happens without ‘const’
  • 1:44 Add ‘const’ keyword
  • 2:05 Create top-level, const val

Thoughts, questions, tips on using ‘const’ in Kotlin? Comment below or share on social media. I’d love to continue the conversation.

I love to meet/talk/discuss and help where I can. If you want to chat or ask a question you can follow me on Twitter, YouTube, Instagram and Facebook.

Check Out My YouTube Channel

Categories: Learning Kotlin


Leave a Reply