Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the syntax for implicit cast operator in dart?

Tags:

dart

I would like to cast instances of my custom class A to int. What is the syntax of the implicit cast operator? (I thought I remembered that there is such a feature but I can't find it on the web)

int a = (new A());
like image 868
jz87 Avatar asked Jun 05 '13 21:06

jz87


1 Answers

You can also use as to help tell the tools "no, really, treat this object as this type".

A good example of this is when you have to deal with dart:html's querySelector() function.

FormElement form = querySelector('#sign-up') as FormElement;

In the above, the object returned by querySelector('#sign-up') is checked that it is really an instance of FormElement.

Learn more at https://www.dartlang.org/docs/dart-up-and-running/ch02.html#operators

like image 196
Seth Ladd Avatar answered Sep 29 '22 03:09

Seth Ladd