FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   object array can't return 'null'?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: object array can't return 'null'?  (Read 270 times)
Sjeiti

WWW
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

WWW
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

WWW
Re: object array can't return 'null'?
« Reply #2 on: Jul 14th, 2004, 3:34pm »

ah... ok...
 
thanks...
 

http://www.sjeiti.com/
Pages: 1 

« Previous topic | Next topic »