liveBook · Manning

Object expression

An object expression is a language construct that creates an object without requiring a separately declared named type.

How 2 Manning books explain it

Kotlin in Action, 2E

An object expression is Kotlin syntax that creates an anonymous object, optionally implementing a class or interfaces, at the point where it is written.

How it is used
Creates local interface or class implementations for event listeners and other ad hoc behaviors.
How deep it goes
Explains syntax, instance creation, interface combinations, variable capture, mutation, and the boundary with SAM conversion.
Examples
Uses MouseListener event handling, stored listeners, and a mutable click counter as concrete examples.
What you can do after
Apply it to implement multi-method listeners, capture local state, and choose between anonymous objects and lambdas.

Read how Kotlin in Action, 2E explains object expression →

F# in Action: A Revised Edition of Get Programming with F#

An object expression is an F# expression that creates an object implementing specified class or interface members without requiring a separately declared type.

How it is used
Uses inline implementations to satisfy interfaces for C# interoperability, runtime-pluggable APIs, and function-shaped contracts.
How deep it goes
Defines syntax and application patterns, but stops short of broader advanced alternatives such as active patterns and statically resolved type parameters.
Examples
Demonstrates multi-member interfaces, time-display adapters, and selectable printer implementations.
What you can do after
Build it from scratch by mapping functions into interface instances without declaring concrete implementation types.

Read how F# in Action: A Revised Edition of Get Programming with F# explains object expression →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.