KT.MAY_BE_CONST

Properties (val) may be const val

This rule identifies and reports properties (val) that may be const val instead. Using const val can lead to better performance of the resulting bytecode as well as better interoperability with Java.

Noncompliant Code

Copy
val myConstant = "abc"

Compliant Code

Copy
const val MY_CONSTANT = "abc"

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html