Annotation Interface AutoObserve
This annotation is typically used when a field references an ArezComponent annotated class that has
ArezComponent.disposeOnDeactivate() set to true. This results in the current component
observing the referenced component and thus preventing it from being disposed for the lifetime of the
current component.
It should be noted that it is preferable for the field that defines the observed component to be marked
with this annotation rather than the method accessor. The reason is that the annotation processor will issue
a warning if a field that the processor identifies as a potential dependency if it is not annotated with
AutoObserve, CascadeDispose or ComponentDependency.
If the element annotated is a method then the method must comply with the additional constraints:
- Must not be annotated with any other arez annotation other than
ReferenceorObservable - Must have 0 parameters
- Must return a value compatible with
ComponentObservable, unlessvalidateTypeAtRuntime()istrue - Must not be private
- Must not be static
- Must not be abstract unless the method is annotated with
ReferenceorObservablein which case it MUST be abstract - Must not throw exceptions
- Must be accessible to the class annotated by the
ArezComponentannotation.
If the element annotated is a field then the field must comply with the additional constraints:
- Must be final
- Must not be private
- Must not be static
- Must be compatible with
ComponentObservable, unlessvalidateTypeAtRuntime()istrue - Must be accessible to the class annotated by the
ArezComponentannotation. - Should not be public. A warning will be generated but can be suppressed by the
SuppressWarningsorSuppressArezWarningsannotations with a key "Arez:PublicField". -
Should not be protected if in the class annotated with the
ArezComponentannotation as the field is not expected to be accessed outside the component. A warning will be generated but can be suppressed by theSuppressWarningsorSuppressArezWarningsannotations with a key "Arez:ProtectedField".
If validateTypeAtRuntime() is set to true then the declared type of the field or method
must be annotated with ArezComponentLike. In this mode, type compatibility is validated at runtime
rather than compile time while still treating the declared type as component-like for validation only.
This annotation is only supported on elements contained within a type annotated by
ArezComponent or ArezComponentLike. Other usages will fail compilation.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanReturn true and the value of the annotated field or method will be validated at runtime rather than compile time.
-
Element Details
-
validateTypeAtRuntime
boolean validateTypeAtRuntimeReturn true and the value of the annotated field or method will be validated at runtime rather than compile time. This is useful when the declared type is annotated withArezComponentLikebut the runtime value is known to implementComponentObservable.- Returns:
- true to defer validation of types until runtime.
- Default:
- false
-