MaterializedRuntimeHint<T> class
abstract
A materialized runtime hint that provides a concrete representation
of its target type T while allowing runtime behavior overrides.
MaterializedRuntimeHint<T> extends AbstractRuntimeHint<T> and implements
ClassGettable<T>, combining the benefits of:
- Generic runtime hints – type-specific hooks for instance creation, method invocation, and field access.
- Materialization – ability to expose type metadata through
Class<T>, which can be used for reflective-like behavior or optimized runtime logic.
Features
-
Materialized Type Representation
toClass()returns aClass<T>representing the typeT.obtainTypeOfRuntimeHint()returns the original type viatoClass().getOriginal().
-
Default Behavior
- Inherits all default no-op runtime hint behaviors from
AbstractRuntimeHint, e.g.,
createNewInstance,invokeMethod,getFieldValue, andsetFieldValue.
- Inherits all default no-op runtime hint behaviors from
AbstractRuntimeHint, e.g.,
-
Equality
- Overrides
equalizedProperties()to include both the materialized class and the runtime type, ensuring consistent equality checks between hints.
- Overrides
Use Cases
- Providing type-aware runtime adapters in JetLeaf.
- Lightweight instrumentation or profiling hooks that need access to the target type.
- Building compile-time optimized runtime hints with full knowledge
of
T.
Example
// Suppose we have a domain model:
class User {
final String name;
final bool isAdmin;
User(this.name, {this.isAdmin = false});
}
// We can create a materialized runtime hint for User:
class UserHint extends MaterializedRuntimeHint<User> {
@override
Hint getFieldValue(User instance, String fieldName) {
if (fieldName == 'isAdmin') {
// Override the isAdmin field dynamically
return Hint.executed(true);
}
return super.getFieldValue(instance, fieldName);
}
}
void main() {
final user = User('Alice');
final hint = UserHint();
// Accessing the type metadata
print(hint.toClass()); // Class<User>
print(hint.obtainTypeOfRuntimeHint()); // User
// Using the runtime hint to intercept a field
final adminValue = hint.getFieldValue(user, 'isAdmin');
print(adminValue.value); // true
}
See Also
- Inheritance
-
- Object
- AbstractRuntimeHint<
T> - MaterializedRuntimeHint
- Implemented types
- Annotations
-
- @Generic(MaterializedRuntimeHint)
Constructors
- MaterializedRuntimeHint()
-
Creates a new materialized runtime hint for type
T.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
-
createNewInstance<
U> (String constructorName, ExecutableArgument argument) → Hint -
Attempts to create a new instance using the given constructor and arguments.
inherited
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString.override -
getFieldValue<
U> (U instance, String fieldName) → Hint -
Attempts to read the value of a field from the given instance.
inherited
-
invokeMethod<
U> (U instance, String methodName, ExecutableArgument argument) → Hint -
Attempts to invoke a method on the given instance.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
obtainTypeOfRuntimeHint(
) → Type -
Returns the runtime Type associated with this hint implementation.
override
-
setFieldValue<
U> (U instance, String fieldName, Object? value) → Hint -
Attempts to write a value to a field on the given instance.
inherited
-
toClass(
) → Class< T> -
Provides a contract for types capable of exposing their associated
runtime Class metadata representation within the JetLeaf reflection system.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited