I want to be able to do something like this:
 
 
		
		
			
			
			
			
				
					
				
					1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
				 
						[ crayon - 5cb9bd084dbc3502613945   inline = "true"   ] Namespace   test 
 
# Import   "<std>" 
 
Using  std . . 
 
Function   Main : Void ( ) 
   Local   foo   : =   New   Foo 
   foo . map [ "mytruck" ]   =   New   Truck 
   foo . map [ "mycar" ]   =   New   Car 
 
   Local   car : Car   =   foo [ "mycar" ]   ' implicitly casts to Car 
   Local   truck : Truck   =   foo [ "mytruck" ]   ' implicitly casts to Truck 
   Local   test : Car   =   foo [ "mytruck" ]   ' implicitly casts to Car, but returns Null since it's the wrong type 
End 
 
Class   Foo 
   Field   map : StringMap <Vehicle>   =   New   StringMap <Vehicle> 
 
   Method  New ( ) 
   End 
 
   Operator   [ ] <T> : T ( name : String )   Where   T   Extends   Vehicle 
     Return   Cast <T> ( map [ name ] ) 
   End 
End 
 
Class   Vehicle 
   Method  New ( ) 
   End 
End 
 
Class   Car  Extends   Vehicle 
   Method  New ( ) 
   End 
End 
 
Class   Truck  Extends   Vehicle 
   Method  New ( ) 
   End 
End 
 
					 
				
			 
		 
[/crayon]
But I get:
 
 
			Error   :   Can 't find overload for '[](...)' with argument types (string) 
Is there a way I can do this?