Field class abstract final

Provides reflective access to class field metadata and value manipulation.

This interface enables runtime inspection and modification of class fields, including access to:

  • Field types and declarations
  • Modifiers (final, const, etc.)
  • Value getters/setters
  • Access permissions

{@template field_interface_features}

Key Features

  • Type-safe field value access
  • Modifier inspection
  • Read/write permission checking
  • Declaring class resolution
  • Signature generation

Implementation Notes

Concrete implementations typically wrap platform-specific reflection objects while providing this uniform interface.

Example Usage

// Get field metadata
final nameField = userClass.getField('name');

// Inspect field properties
print('Field type: ${nameField.getType<String>().getName()}');
print('Is final: ${nameField.isFinal()}');

// Access field values
final currentName = nameField.getValue(userInstance);
nameField.setValue(userInstance, 'New Name');

{@endtemplate}

Inheritance
Implemented types

Constructors

Field.declared(FieldDeclaration declaration, Declaration parent, ProtectionDomain domain)
Creates a Field instance from reflection metadata.
factory

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

asAnnotation() → AnnotationFieldDeclaration?
Returns the annotation field declaration if it is an annotation field declaration, otherwise null.
asEnum() → EnumFieldDeclaration?
Returns the enum field declaration if it is an enum field declaration, otherwise null.
asRecord() → RecordFieldDeclaration?
Returns the record field declaration if it is a record field declaration, otherwise null.
checkAccess(String operation, DomainPermission permission) → void
Verifies access permissions before performing sensitive operations.
inherited
getAllDirectAnnotations() → Iterable<Annotation>
Gets all annotations applied to this element.
inherited
getAuthor() → Author?
Retrieves the Author annotation applied to this element, if present.
inherited
getDeclaration() → Declaration
Gets the type declaration metadata for this class.
inherited
getDeclaringClass<D>() → Class<D>
Gets the class that declares this method.
inherited
getDirectAnnotation<A>() → A?
Gets a single annotation by type, if present.
inherited
getDirectAnnotations<A>() → Iterable<A>
Gets all annotations of a specific type.
inherited
getModifiers() → List<String>
Returns the list of modifiers associated with this source element.
inherited
getName() → String
Gets the declared name of the source.
inherited
getParent() → Declaration
Gets the parent declaration of this field.
getPosition() → int
The position of the enum value as-is in the enum class
getProtectionDomain() → ProtectionDomain
Gets the protection domain governing access to this element.
inherited
getReturnClass() → Class<Object>
Gets the return type of the method.
inherited
getReturnType() → Type
Gets the return type of the method.
inherited
getSignature() → String
Gets the executable signature as a string.
inherited
getType() → Type
Gets the type of the field.
getValue([Object? instance]) → dynamic
Gets the field's value from an instance.
getValueAs<T>([Object? instance]) → T?
Gets the field's value with type safety.
getVersion() → Version
Retrieves the version metadata associated with this declaration, if any.
inherited
hasDirectAnnotation<A>() → bool
Checks if this element has a specific annotation.
inherited
isAbstract() → bool
Checks if this field is abstract.
isAnnotationField() → bool
Checks if this field is an annotation field.
isConst() → bool
Checks if this field is const.
isEnumField() → bool
Checks if this field is an enum field.
isFinal() → bool
Checks if this field is final.
isLate() → bool
Checks if this field is late.
isNamed() → bool
Checks if this is a named field.
isNullable() → bool
Returns true if the field is nullable.
isPositional() → bool
Checks if this is a positional field.
isPublic() → bool
Checks if this element is public.
inherited
isReadable() → bool
Determines whether this field can be read from (i.e., retrieved a value) through Jetleaf's reflective or dependency injection mechanisms.
isRecordField() → bool
Checks if this field is a record field.
isStatic() → bool
Checks if this field is static.
isTopLevel() → bool
Checks if this field is a top-level field.
isWritable() → bool
Determines whether this field can be written to (i.e., assigned a value) through Jetleaf's reflective or dependency injection mechanisms.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setValue(Object? instance, dynamic value) → void
Sets the field's value on an instance.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited