Sealed class
annotate classes with @Sealed to generate sealed class code.
==, hashCode and toString are generated for each data class. equality will specify how equality is implemented. see Equality and WithEquality if you want to override equality for all sub classes or only a specified group. by default all equalities are Equality.data.
annotated element should be an abstract private class without any super class, mixin or interfaces except Object. it's name without _ denotes generated sealed super abstract class name and sub data classes name prefix.
all of the class methods are considered manifest for sealed data sub classes. method names are transformed to sub data class names. methods should only have positional arguments with names becoming data class field names and types becoming their types. types can be nullable.
Top class name is derived from manifest class name and it
will be also used as sub class name prefixes. You can not
override top class name but you can override prefix for all
sub classes by using WithPrefix and override full sub class
names by using WithName. For example annotate top class by
@WithPrefix('')
to remove prefix generation.
each generated sealed abstract super class is annotated with @SealedManifest targeting class which is annotated by @Sealed. it prevents analyzer for complaining that the class is unused.
if language level is before 2.12.0 all generated fields are considered nullable.
for example:
@Sealed()
abstract class _Weather {
void sunny();
void rainy(int rain);
void windy(double velocity, double? angle);
}
- Annotations
-
- @Target({TargetKind.classType})
Constructors
- Sealed()
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited