loadClass<T> abstract method

Class<T>? loadClass<T>(
  1. String className, [
  2. ProtectionDomain? domain
])

Loads a class by its fully qualified name with caching support.

Type Parameters:

  • T: The expected class type for type safety

Parameters:

  • className: The fully qualified class name (e.g., 'dart:core/string.dart.String')
  • domain: Optional protection domain for security context

Returns:

  • A cached or newly loaded Class<T> instance
  • null if the class cannot be found or loaded

Caching Behavior

  • First checks the primary class cache for existing instances
  • If not cached, delegates to findClass for loading
  • Caches successful results for future requests
  • Updates related caches (subclasses, interfaces, mixins)

Example

// Load with type safety
final stringClass = await loader.loadClass<String>('dart:core/string.dart.String');

// Load with custom domain
final userClass = await loader.loadClass<User>(
  'com.example.User',
  ProtectionDomain.application()
);

Performance Notes

  • Subsequent calls for the same class return cached instances
  • Cache lookups are O(1) for qualified name access
  • Related type information is pre-computed and cached

Throws:

Implementation

Class<T>? loadClass<T>(String className, [ProtectionDomain? domain]);