no maps with array values?

Monkey Forums/Monkey Programming/no maps with array values?

dmaz(Posted 2011) [#1]
see http://www.monkeycoder.co.nz/Community/post.php?topic=1405&post=12690

this seems like a bug to me as it doesn't seem you can use arrays for templated classes at all...

Local amap:StringMap<Int[]> = New StringMap<Int[]>
(syntax error - expecting identifier)

Local amap:StringMap<IntObject[]> = New StringMap<IntObject[]>
(syntax error - expecting '>')

Local amap:Map<String,Int[]> = New Map<String,Int[]>
(syntax error - expecting identifier)

this errors as well
Class mine<T[]>
(syntax error - expecting '>')


Samah(Posted 2011) [#2]
Local amap:StringMap<Int[]> = New StringMap<Int[]>
(syntax error - expecting identifier)

Local amap:StringMap<IntObject[]> = New StringMap<IntObject[]>
(syntax error - expecting '>')

Local amap:Map<String,Int[]> = New Map<String,Int[]>
(syntax error - expecting identifier)

These don't work because in Monkey an array is not an object.

Class mine<T[]>
(syntax error - expecting '>')

This doesn't work because in Monkey an array is not an object.


marksibly(Posted 2011) [#3]
Hi,

Yes, arrays (and strings) are not 'objects' in Monkey, so can't be used with generic classes.

Your best bet is probably to 'encapsulate' the array in a class - or, use a 'Stack' instead.


Samah(Posted 2011) [#4]
@marksibly Your best bet is probably to 'encapsulate' the array in a class - or, use a 'Stack' instead.

As I said in the other thread, use IntArrayList instead. :)