OOP
Intermediate 2 min read
Object Expressions as Anonymous Classes
Create one-off implementations inline
Kotlin Academy
Kotlin Engineer
Object expressions create anonymous class instances that can implement interfaces, extend classes, and capture variables from the enclosing scope. Unlike SAM conversions (which only work for single-abstract-method interfaces), object expressions work with any interface or class. They are the go-to tool for one-shot implementations of multi-method interfaces like listeners.
#kotlin
#object-expression
#anonymous-class
#oop