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

shared annotation

The shared annotation marks a declaration as being visible outside the scope in which it is defined, or a package as being visible outside the module to which it belongs.

It is also applied to module imports which are visible in the API of the module, and therefore must be exported to clients of the module.


On a declaration:

shared void method() {

On a package:

shared package;

On a module import:

module "1.0" {
    shared import "4.5.1";


Visibility is a critical concern when building modular systems. Clients of a module should not be able to come to 'accidently' depend upon details of the module which are not considered part of its well-defined API. Therefore, Ceylon requires that exported program elements be explicitly marked as such.

By default, a declaration may not be referred to outside the scope in which it is declared. The shared annotation makes a declaration visible to any client of the package or type to which it belongs.

See also