Robert,

java.lang.Object
  +--java.util.AbstractCollection
        +--java.util.AbstractList
              +--java.util.ArrayList
and

java.lang.Object
  +--java.util.AbstractCollection
        +--java.util.AbstractList
              +--java.util.Vector

So you cannot cast an ArrayList to a Vector. You could only do this if
a) ArrayList were derived from Vector (it isn't), or if
b) Vector were an interface instead of a class (it isn't), and ArrayList 
implemented Vector.

Yes, both ArrayList and Vector implement the List interface (which extends 
the Collection interface). This just means you can treat instances of both 
classes either as a Collection or a List. It does not mean that you can 
cast an ArrayList to a Vector, or viceversa.

Joe

-----Original Message-----
From:   Robert Hargreaves [SMTP:[EMAIL PROTECTED]]
Sent:   Friday, March 03, 2000 2:25 PM
To:     Jonas Users Group (E-mail)
Subject:        findAll() will not cast to Vector

Dear All

I have a findAll method for a CMP enitity bean. I have previously had to
cast to and ArrayList when calling this method. But now because I need to
use a Vector instead (for backward compatability reasons), I have done:

AddressHome adrHome = (AddressHome)initialContext.lookup("Address");
Vector v = (Vector)adrHome.findAll();
                
I get the following exception thrown: java.lang.ClassCastException:
java.util.ArrayList.

The method declaration in the home interface of the bean is:
public Collection findAll() throws RemoteException, FinderException
which suggests I can cast to a Vector (correct me of I'm wrong).

The only solution is to go back to casting to an ArrayList and then iterate
through it passing each element to a Vector, which works but isn't ideal.

Any suggestions?

Regards,

Robert Hargreaves



----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

Reply via email to