isWritable abstract method

bool isWritable()

Determines whether this field can be written to (i.e., assigned a value) through Jetleaf's reflective or dependency injection mechanisms.

A field is considered writable if all of the following are true:

  1. It is not static — writable fields must belong to an instance.
  2. It is not const — constant fields are compile-time constants.
  3. It is either:
    • non-final, meaning it can always be reassigned, or
    • late final, meaning it can be assigned once after construction.

Examples

class Example {
  final User user1;           // ❌ not writable
  late final User user2;      // ✅ writable (late final)
  User? user3;                // ✅ writable (mutable)
  static User? user4;         // ❌ not writable (static)
  const String key = 'abc';   // ❌ not writable (const)
}

final fields = Class.of(Example).getFields();
for (final field in fields) {
  print('${field.getName()}: ${field.isWritable()}');
}

Output:

user1: false
user2: true
user3: true
user4: false
key: false

This method performs an internal access check to ensure the caller has DomainPermission.READ_FIELDS before inspecting the field’s properties.

Implementation

bool isWritable();