|
Author |
Topic: object array can't return 'null'? (Read 270 times) |
|
Sjeiti
|
object array can't return 'null'?
« on: Jul 14th, 2004, 3:03pm » |
|
Why is it that an array of ints, floats or Strings returns 'null' for an empty index and an array of Objects returns an error...: Code:void setup() { String[] lAsd = new String[10]; lAsd[0] = new String("j"); println(lAsd[0]); println(lAsd[1]); println(); Test[] lTst = new Test[10]; lTst[0] = new Test(); println(lTst[0]); //println(lTst[1]); } class Test { Test() { } } |
| (uncomment commented line) Is there a way to test if a spot in an array of objects is null or not? ...or do I have to use Vectors for this? gr.. ..Sjeiti
|
http://www.sjeiti.com/
|
|
|
arielm
|
Re: object array can't return 'null'?
« Reply #1 on: Jul 14th, 2004, 3:17pm » |
|
an array of objects does give "null" for empty slots: Object[] foo = new Object[10]; if (foo[0] == null)... it's just that you're going through println(), which does something like: objectInQuestion.toString() that is the cause of the error.
|
Ariel Malka | www.chronotext.org
|
|
|
Sjeiti
|
Re: object array can't return 'null'?
« Reply #2 on: Jul 14th, 2004, 3:34pm » |
|
ah... ok... thanks...
|
http://www.sjeiti.com/
|
|
|
|