ADocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
final class in Dart is a class modifier that completely restricts subtyping outside of its declaring library. It guarantees that the class hierarchy is closed to external modification, preventing external code from either extending or implementing the class, while still permitting unrestricted instantiation.
Core Mechanics
- Instantiation: A
finalclass can be instantiated from any library. - Extension (
extends): Prohibited outside the declaring library. Allowed within the declaring library. - Implementation (
implements): Prohibited outside the declaring library. Allowed within the declaring library. - Mixin Application (
with): Prohibited outside the declaring library.
Syntax and Library Boundaries
The behavior of afinal class strictly depends on the library boundary (typically the file boundary, unless part directives are used).
File 1: core_library.dart (Declaring Library)
external_module.dart (External Library)
Modifier Propagation Rules
Dart enforces strict modifier propagation to prevent external code from bypassing thefinal restriction via a subclass. If a class extends or implements a final class within the same library, that subclass must be explicitly marked with one of the following modifiers:
final: Completely closes the subclass to external subtyping.base: Allows external extension, but prohibits external implementation.sealed: Creates an abstract, exhaustively switchable subclass that also restricts external subtyping.
Interaction with Other Modifiers
abstract final class: The class cannot be instantiated anywhere, and cannot be subtyped outside its own library. It acts purely as an internal base class or interface.interfacevsbasevsfinal:interfaceblocks externalextends.baseblocks externalimplements.finalblocks both externalextendsandimplements.
Master Dart with Deep Grasping Methodology!Learn More





