Tsallaka zuwa abun ciki
Justice Tech School

Type Tests and Casts

is checks a type and as casts. Promotion makes is checks smarter.

Example
void show(Object o) {
  if (o is String) print(o.length);
  else if (o is int) print(o + 1);
  var s = o as Object;
  print(s.runtimeType);
}
void main() { show("abc"); show(4); }

Exercise

Test a type.

o  String

Quiz Test

What does promotion do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.