| 10 | |
| 11 | This also works for object variables: |
| 12 | {{{ |
| 13 | class Person |
| 14 | |
| 15 | var _name = '' # typed as String |
| 16 | var _age = 0 # typed as int |
| 17 | }}} |
| 18 | |
| 19 | If the inferred type is not suitable, perhaps because you need a more general type, you can provide one explicitly or even typecast the right-hand side: |
| 20 | {{{ |
| 21 | class Person |
| 22 | |
| 23 | var _name = '' to dynamic |
| 24 | var _age as int64 = 0 |
| 25 | |
| 26 | def foo |
| 27 | i = 0 to int64 |
| 28 | j as int64 = 0 |
| 29 | }}} |
| 30 | |
| 31 | Sometimes you want the variable to be typed as a base class because you may assign other things to it in the future: |
| 32 | {{{ |
| 33 | shape = Circle() to Shape |
| 34 | |
| 35 | share as Shape = Circle() |
| 36 | }}} |
| 37 | |
| 38 | |
| 39 | See also: AdditionalDoc, TypesOverview |