Runnable class abstract interface

A simple contract for objects that can be executed.

The Runnable interface is inspired by Java's Runnable and is commonly used to define a task or unit of work that can be run, typically on a thread, executor, or lifecycle callback.

This interface is useful for generic task execution, background processing, or deferred logic.

Example:

class Task implements Runnable {
  @override
  FutureOr<void> run() {
    print('Running a task...');
  }
}

void execute(Runnable runnable) {
  runnable.run();
}

void main() {
  final task = Task();
  execute(task); // Output: Running a task...
}

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run() FutureOr<void>
Executes the task encapsulated by this instance.
toString() String
A string representation of this object.
inherited

Operators

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