posted 18 years ago
Hi,
The problem is that when you initialize a variable, the type of the init value must match the type of the variable.
Here, you have an Object type variable named "objects2" and you have a Pizza[] init value. Types don't match.
Arrays are extensions of the Object class. It is then possible to affect an array to an Object variable. The following code is valid:
Object[] objectsTab = {new Pizza(), new Pizza()};
Object obj = objectsTab;
I guess the difference is that during initialization, the JVM will allocated memory space to store the init value. I think that's why types must match, so that the JVM will have necessary information to allocate enough memory.
Sebastien