Back to Intellij Community

DelegationToVarProperty

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/DelegationToVarProperty.html

2025.3-rc-2508 B
Original Source

Reports interface delegation to a var property.

Only initial value of a property is used for delegation, any later assignments do not affect it.

Example:

class Example(var text: CharSequence): CharSequence by text

The quick-fix replaces a property with immutable one:

class Example(val text: CharSequence): CharSequence by text

Alternative way, if you rely on mutability for some reason:

class Example(text: CharSequence): CharSequence by text {
      var text = text
  }