ActionScript 3 Language Specification |
|||
| ActionScript 3.0 Language Specification > 6 Types > 6.3 Type annotations | |||
A type annotation can be used when declaring a variable, a function parameter, or a function return type to guarantee that the associated value will be a member of a specific data type. A type annotation is a suffix that takes the form of a colon character (:) followed by a data type. Examples of type annotations follow:
var num:Number
function foo(str:String) : Boolean {}
In the standard dialect, type mismatches are not reported at compile time. Rather, a runtime type conversion is attempted and an error is reported if the type conversion fails. For example, the following example not only compiles in the standard dialect, but also does not cause a runtime error:
var num : Number = "1.23" trace(num is Number) // output: true
In the strict dialect, type mismatches are reported as compile-time errors. Accordingly, the previous example does not compile in strict mode because the string value "1.23" is not a member of the Number data type. In other words, a variable v that uses the following syntax will not compile unless v is a member of data type T:
var v:T
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification55.html