Object expression
An object expression is a language construct that creates an object without requiring a separately declared named type.
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.
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 →
What to know first
- lambdaA lambda is an expression that defines an unnamed function by specifying its parameters and body, producing a callable value.
- methodA method is a callable operation associated with a type, class, or object and invoked through that association.
Related concepts
- expressionkind of · An expression is a syntactically formed combination of values, names, operators, or other terms that denotes or evaluates to a value or result.
- interfaceimplements · An interface is a defined contract or boundary that specifies the operations, capabilities, or data shape through which a type or component interacts with others.
- natural language interfaceimplements · A natural language interface enables interaction with a system through human-language text or speech.
- object declarationcontrasts with · An object declaration is a Kotlin declaration that defines a singleton object and creates its sole instance as part of the declaration.
Questions about object expression
What is object expression?
An object expression is a language construct that creates an object without requiring a separately declared named type.
Which Manning books explain object expression?
Kotlin in Action, 2E and F# in Action: A Revised Edition of Get Programming with F#.
What should I know before learning object expression?
Manning books that teach object expression usually introduce lambda and method first.
What is the difference between object expression and anonymous class?
An object expression is a language construct that creates an object without requiring a separately declared named type. An anonymous class is a class declared and instantiated without an explicit source-level name.
What is object expression a kind of?
Object expression is a kind of expression. An expression is a syntactically formed combination of values, names, operators, or other terms that denotes or evaluates to a value or result.
What is object expression also called?
Object expression is also called anonymous object.
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.

