0Pricing
Kotlin Academy · Lesson

Extension Properties and Computed Extensions

Add computed properties to existing classes without subclassing.

Extension Properties

Extension properties add computed properties to existing types without subclassing. They have no backing field.

Read-Only Extension Property

Define a getter to create a computed extension property.
val String.wordCount: Int
    get() = trim().split(Regex("\\s+")).size
println("hello world kotlin".wordCount)  // 3

All lessons in this course

  1. Extension Functions: Syntax and Dispatch Rules
  2. Extension Properties and Computed Extensions
  3. Scoped Extensions and Companion Extensions
  4. Practical Extensions: Context, View & String Helpers
← Back to Kotlin Academy