Most Dart types are just class/interface types. Unlike Java, Dart does not have "primitive" value types that are not interfaces, so in Dart int
, double
, String
, bool
and Null
normal interfaces which are subtypes of Object?
(and of Object
except for Null
), and the values are just normal objects.
Dart does have some types and type constructors which are not class/interface types, or which have specific rules preventing you from implementing them. In particular:
void
- Equivalent to Object?
, but you're not allowed to use the value. You can return any value from a void
function, but no-one is supposed to use it.
dynamic
- Equivalent to Object?
, but without static type checking. You can cast any value to dynamic
, and then use it as any type, and you get run-time errors if you make a mistake.
Never
- an empty subtype of all types. A function returning Never
is guaranteed to throw.
type Function(argTypes)
- A function type. Some values are functions. They're still objects, but are not class/interface instances. Subtypes of the interfaces Function
and Object
.
FutureOr<type>
- a supertype of both type
and Future<type>
.
type?
- a nullable type. A supertype of both type
and Null
.
Then the following interfaces have restrictions which prevents you from implementing them in your own classes: Null
, int
, double
, num
, bool
, String
, and Function
.
So, for function types, you write them as, fx, int Function(int, {int y})
.