@AutoObserve
The @AutoObserve annotation keeps a referenced
ComponentObservable observed for the full alive lifetime of the owning
component. This is primarily useful when a component references another
@ArezComponent configured with
disposeOnDeactivate = true and the owner should keep
that referenced component alive while the owner itself is alive.
The annotation can be placed on:
- a final field
- a concrete zero-argument method
- an abstract
@Observablegetter - an abstract
@Referenceaccessor
For field targets, prefer package access. The annotation processor emits suppressable warnings for public fields and
for protected fields unless the field is inherited from a parent class in a different package.
When the target can return null, the generated auto-observer skips null values safely. When paired with
@Reference, auto-observation forces the reference to resolve, even for
LAZY references.
Use @AutoObserve when you want liveness coupling. Use
@CascadeDispose when the owner should explicitly dispose the target. Use
@ComponentDependency when disposal of the target should trigger disposal
or nulling of the owner reference.
An example:
@ArezComponent
public abstract class Dashboard
{
// The session should stay alive while the dashboard is alive.
@AutoObserve
@Nonnull
final Session _session;
...
// Retargeting the observable property automatically updates the auto-observer.
@AutoObserve
@Observable
@Nullable
public abstract Workspace getWorkspace();
...
// Lazy references are force-resolved when auto-observed.
@AutoObserve
@Reference( load = LinkType.LAZY )
@Nullable
public abstract Workspace getPinnedWorkspace();
@ReferenceId
@Observable
@Nullable
public abstract Integer getPinnedWorkspaceId();
...
}