remote class loading for the purpose of casting

i have an object, to which i append a container.

this container has objects of type that are not known on the

remote host.

// this is the local machine

publicclass Record1implements Interface1, Serializable{

publicdouble d = -1;

public List<String>;

}

....

publicclass Agentimplements Runnable{

.....

publicvoid run(){

...

List list =new ArrayList<Interface1>()

list.add(record1);

list.add(record2);

Socket sok = serverSocket.accept();

ObjectOutputStream oos =new ObjectOutputStream(sok.getOutputStream());

oos.writeObject(list);

}

.....

========================

// this is the remote host

......

ObjectInputStream ois =new ObjectInputStream(sok.getInputStream());

List list = (List) ois.readObject();

Iterator it = list.iterator();

while(it.hasNext()){

Interface1 record = (Interface1) it.next();

// error.... ClassCastException

i can load the class that i want to cast:

Class myClass = myLoader.loadClass("Record1");

but then what?

how do i usemyClass to cast-out the

contents oflist.

is this even possible.

summary:

all i want to do is cast out the contents of a

container with a dynamically loaded Class.

please help.

[2184 byte] By [suppona] at [2007-11-27 7:06:43]
# 1
Any class that you are loading dynamically has to obey an interface or extend a base class that is already installed at the JVM where you are running the code. You can only cast to that interface/base class.Otherwise you can't even write the code and compile it, let alone execute
ejpa at 2007-7-12 18:58:00 > top of Java-index,Core,Core APIs...