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)
   ArrayList
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: ArrayList  (Read 2044 times)
benelek

35160983516098 WWW Email
ArrayList
« on: Apr 12th, 2003, 9:20am »

g'day all,
 
  im having some trouble understanding the relationship between the Object class and its children classes. for example, why doesn't the following work, if an int is a subclass of Object? and if you can't assign a value of type 'int' to a variable of type 'Object', what can you assign to a variable of type 'Object'?
 
Code:
Object moo = 15;

 
and...
 
Code:
Object moo;
int mooner=15;
moo=mooner;

 
-jacob
 
benelek

35160983516098 WWW Email
Re: ArrayList
« Reply #1 on: Apr 12th, 2003, 9:44am »

uh... looks like i got ahead of myself with the topic of the post anyway, here's the part about the ArrayList class:
 
Code:

int mooner = 15;
Integer mooner2 = new Integer(mooner);
Object moo = new Integer(mooner);
 
ArrayList mooList = new ArrayList();
  mooList.add(moo);
  //mooList.add(mooner); //try this.
  mooList.add(mooner2);
   
println(random(5));
println(mooList.get(0).getClass());
println(mooList.get(1).getClass());

 
using the "Integer" class works as an Object, but using an "int" doesnt. isnt the "int" class a subclass of Object?
 
-jacob
 
fry


WWW
Re: ArrayList
« Reply #2 on: Apr 13th, 2003, 1:23am »

nope, the rule of thumb is that only the all-caps names are subclasses of Object. int, float, byte, char, etc are basic elements that aren't classes. this is done primarily for speed reasons in the java virtual machine.
 
benelek

35160983516098 WWW Email
Re: ArrayList
« Reply #3 on: Apr 13th, 2003, 3:44am »

rightyo *major stumbling block falls*
 
thanks
 
-jacob
 
Pages: 1 

« Previous topic | Next topic »