Class Annotations

[COG] and [Plain]

Classes in ABS can be instantiated in the current COG by using the standard new expression, or can be instantiated in a new COG by using the new cog expressions. In most cases, however, a class should either always be instantiated in a new COG, because it introduces a new component, or it should always be instantiated in the current COG, because it is part of a component. To guarantee that a certain class is always instantiated in only one of these to ways one can use the class annotations [COG] or [Plain]. The [COG] annotation ensures that classes are always instantiated in a new COG, [Plain] ensures that classes are always instantiated in the current COG.

Example

module Test;
interface I {};
[COG] class Foo implements I { }
[Plain] class Bar implements I { }

{
   I i = new Foo(); // type-error
   I j = new cog Foo(); // ok
   I k = new Bar(); // ok
   I k = new cog Bar(); // type-error
}