Dynamic/Runtime java casting

B

Berlin Brown

In an earlier thread. I asked about ClassCast and ClassLoader issues.
I think this could be solved with dynamic casting. Something along the
lines of:

Method m = this.getClass().getMethod("mult",
new Class[]{o.getClass(), int.class)};
m.invoke(new Object[]{o, new Integer(factor));

but cleaner:

Class c = obj.getClass();
Object o2 = session.getAttribute("some.str");
String someStr = (String) c.cast(o2);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,377
Latest member
Zebacus

Latest Threads

Top