resolve method

Class? resolve([
  1. Class? fallback
])

Resolves this ResolvableType to a Class, returning null if the type cannot be resolved.

This is the primary method for converting a ResolvableType to a concrete Class instance that can be used for reflection operations, instantiation, and other runtime type operations.

Parameters:

  • fallback: Optional Class to return if resolution fails

Returns:

  • Class instance representing this ResolvableType
  • The fallback Class if provided and resolution fails
  • null if resolution fails and no fallback is provided

Example:

final stringType = ResolvableType.forClass(String);
final listType = ResolvableType.forClass(List<int>);
final unknownType = ResolvableType.NONE;

final stringClass = stringType.resolve();
print(stringClass?.getType()); // String

final listClass = listType.resolve();
print(listClass?.getType()); // List<int>

final unknownClass = unknownType.resolve();
print(unknownClass); // null

// With fallback
final objectFallback = Class.forType(Object);
final unknownWithFallback = unknownType.resolve(objectFallback);
print(unknownWithFallback?.getType()); // Object

// Useful for safe operations
void processType(ResolvableType type) {
  final clazz = type.resolve();
  if (clazz != null) {
    print("Processing ${clazz.getType()}");
    // Perform operations with the resolved class
  } else {
    print("Cannot resolve type");
  }
}

Implementation

Class? resolve([Class? fallback]) {
  if (_resolved != null) return _resolved;

  final resolved = _resolveClass();
  _resolved = resolved;
  return resolved ?? fallback;
}