Wiki

Changes between Version 4 and Version 5 of TypeInference

Show
Ignore:
Timestamp:
11/22/10 20:27:46 (13 years ago)
Author:
todd.a
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TypeInference

    v4 v5  
    33Although you can explicitly declare the type of a local variable, you don't have to: 
    44{{{ 
     5#!cobra 
    56# the long way: 
    67i as int = 0 
     
    1314This also works for object variables: 
    1415{{{ 
     16#!cobra 
    1517class Person 
    1618 
     
    2123If 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: 
    2224{{{ 
     25#!cobra 
    2326class Person 
    2427 
     
    3336Sometimes you want the variable to be typed as a base class because you may assign other things to it in the future: 
    3437{{{ 
     38#!cobra 
    3539    shape = Circle() to Shape 
    3640 
     
    4246Type inference also occurs for the types of generic lists, sets and dictionaries: 
    4347{{{ 
     48#!cobra 
    4449    names = ['foo', 'bar']  # List<of String> 
    4550    numbers = {1, 2, 3}     # Set<of int>