First-class objects

Could someone please tell me the definition of "first-class object"?
[82 byte] By [ajavagreenhorn] at [2007-9-26 4:21:43]
# 1

I don't know exactly what it means, but from the way I've seen it used, it appears to basically mean that "something" is an object just like any other object. That as far as the language is concerned, it *is* an object.

The two examples that leap to mind in Java-land are arrays and classes.

WhateverClass[] x = new WhateverClass[666];

x is an array of WhateverClass objects. That means each element of x (that is x[0], x[1], etc.) is an object. However, x itself is also an object (well, an object reference, really, but so is every other variable in Java). And the class of x is a subclass of java.lang.Object. So that means you can do x.toString() and x.getClass(), and you can say WhatEverClass[] y = x and assign another object reference to it just like a reference to an object of any other class.

I don't know if classes, per se, are first class objects. However, for every class that exists in the VM, there is a corresponding java.lang.Class object. Same rules apply--invoke methods, assign, etc.

jverd at 2007-6-29 17:26:09 > top of Java-index,Archived Forums,New To Java Technology Archive...