Dart Type Test Operators
Type Test Operators in Dart
These operators are used to check the types of expressions at runtime. Dart is a typed language, and we often want to assert that a value is of a correct type or change the type of a value to a related type.
Consider the following table that contains the list of all the type test operators in Dart :
Sr. | Operator | Description |
1. | as | It is used for typecast. |
2. | is | It returns TRUE if the object has specified type. |
3. | is! | It returns TRUE if the object has not specified type. |
Program
Consider the following code in Dart that explains the type test operators in Dart,
void main( )
{
String a = ' JavaTpoint ' ;
// is type operator
var b = a is String ;
print( ' Is JavaTpoint a string ? ' ) ;
print( b ) ;
// is! type operator
var c = a is! String ;
print( ' Is JavaTpoint not a string ? ' ) ;
print( c ) ;
}
Output
Is JavaTpoint a string ?
True
Is JavaTpoint not a string ?
False