Home > Software engineering >  Future without a type - what does it mean?
Future without a type - what does it mean?

Time:10-15

Is returning a Future without a type means Future<void>?

Future validateUsername(String value) async {}

CodePudding user response:

If no type is specified as generic type dynamic is used. So it means Future<dynamic>.

You can check it inside dartpad future

CodePudding user response:

Future with no explicit type argument is shorthand for Future<dynamic>.

In general, if no type argument is specified, the least constrained type allowed is assumed. For most generics, that means dynamic. In cases where the generic constrains the type argument, that means that constraining base type. For example, given:

class Foo {}

class Generic<T extends Foo> {}

then Generic without any explicit type argument would be shorthand for Generic<Foo>.

  • Related