Note: information on this page refers to Ceylon 1.0, not to the current release.


An object declaration is an anonymous class that is implicitly instantiated exactly once at the place it is defined, and nowhere else. As such it is also a value.


A trivial object declaration looks like this:

object o {
    /* declarations of object members */


Type parameters and parameters

An object declaration does not have parameters or type parameters.


This reference uses object (in a monospaced font) when discussing an object declaration, which is the subject of this page. A class instance may be referred to as an object (in the usual font). In other contexts we often use the term anonymous class.

Toplevel objects

A toplevel object is a singleton.

Nested objects

An object declaration may occur inside the body of a class, function, or value declaration. In this case, a new instance of the object is instantiated each time the body is executed.

An object declaration may not occur in the body of an interface, since objects are implicitly stateful (the state being the reference to the instance itself).

Shared objects

An object may be annotated shared, meaning it is visible outside the scope in which its declaration occurs.

Actual objects

An object may be annotated actual, meaning that it refines an attribute of a supertype of the class or interface to which it belongs.


ClassDeclaration.anonymous can be used to determine whether a given ClassDeclaration represents an anonymous class.

The instance is a value, so can be manipulated ValueDeclaration and Value or Attribute.


The permitted members of objects are classes, interfaces, methods, attributes, and objects.

See also