Wiki

Changes between Version 1 and Version 2 of TypeInference

Show
Ignore:
Timestamp:
07/23/09 19:56:32 (15 years ago)
Author:
Chuck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TypeInference

    v1 v2  
    88}}} 
    99The type of the variable on the left is taken to be the type of the expression on the right. 
     10 
     11This also works for object variables: 
     12{{{ 
     13class Person 
     14 
     15    var _name = ''  # typed as String 
     16    var _age = 0    # typed as int 
     17}}} 
     18 
     19If 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{{{ 
     21class 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 
     31Sometimes 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 
     39See also: AdditionalDoc, TypesOverview