Casting using classname

usually u can cast asinstance=(classTypeOf Instance)Object

I want to cast the result of initCtx.lookup(String jndiName) to a class

CustomerLocalHome =

sampleMethode(String CustomerLocalHomeClassName) initCtx.lookup(String jndiName)

so sampleMethod return must be type of CustomerLocalHome

In JDK 1.5 cast problem has been solved with runtime solution no need to use

type of an object ,but so many IDE's have their own jdk and u cannot change their jdk

I would appritiate if any body tell me

casting by string classname not class type

[601 byte] By [hrsat110] at [2007-9-30 6:50:47]
# 1

> I want to cast the result of initCtx.lookup(String

> jndiName) to a class

> CustomerLocalHome =

> sampleMethode(String CustomerLocalHomeClassName)

> initCtx.lookup(String jndiName)

Think about your problem again. - You are working with a bad design.

if you don't know at compile-time the reference type you need, then you will never be able to compile your code anyway.

You can't change an object's type at runtime. - At runtime, if the object is of the correct type, the cast makes no difference to the way the program will execute, so trying to

mattbunch at 2007-7-1 22:08:26 > top of Java-index,Administration Tools,Sun Connection...
# 2
Thank u for your commentbut some times u need to write dynamic program,get a meta data from a file and and cast your object in runtime(is so common in writing frame works)then using reflection in java u can invoke methods or get or set anything
hrsat110 at 2007-7-1 22:08:26 > top of Java-index,Administration Tools,Sun Connection...
# 3

> Thank u for your comment

> but some times u need to write dynamic program,get a

> meta data from a file and and cast your

> object in runtime(is so common in writing frame works)

It might well be, but not in Java. It makes no sense in Java.

If you're not convinced, how about posting the code you think you'd be able to use were you able to perform the cast. (How about using the notation (DynamicCast to "MyClass") to indicate where you'd use the dynamic cast if it was available

> then using reflection in java u can invoke methods or

> get or set anything

The type of the reference is irrelevant when using reflection - only the runtime type is important, so casting is no use - like I said before you can not change the type of an object at runtime. Perhaps you don't really understand the purpose of a cast in Java?

mattbunch at 2007-7-1 22:08:26 > top of Java-index,Administration Tools,Sun Connection...