Arrays and Null

Monkey Forums/Monkey Programming/Arrays and Null

muddy_shoes(Posted 2011) [#1]
I'm aware that there are some issues with arrays and typecasting, but is there some reason why the type-checking barfs at the idea of a null array reference?

I come to ask this because I'm looking at a problem in the Box2D port where I'm emulating parts of the Flash API and there are places where that API allows variable numbers of argument. To provide something similar, I wanted to pass in an optional array with a default value of null but the Monkey compiler won't have any attempt to assign null to an array reference or compare an array reference to null.

There are ways around this, obviously, but it seems a bit inconsistent to not allow this. It's not as if the references can't be null as simply not initialising them creates a reference that fails an "If ref" test even if "If ref <> Null" is disallowed for whatever reason.


Samah(Posted 2011) [#2]
Default it to the empty array then.
Method MyMethod:Void(myarray:Object[] = [])



muddy_shoes(Posted 2011) [#3]
As I said, "there are ways around this, obviously". Using the empty array causes an initialisation, which seems unnecessary when a null would do.