java - Casting to Unknown Type When Only Given Class Name as a String of That Type -


I currently have a list of objects (using Java 1.3), and we say that I'm one of the objects I wanted to return to List.get (i) one of the types from which I only know the name of class as string. Basically, how I object o = (classname) list.get (i); Where className is a string variable of a classname.

I thought I could use class.forName (className) list.get (i), but I got a syntax error to claim that I forgot the semicolon.

Unfortunately, since I am using Java 1.3, I do not have access to class.cast (object) method.

What is the name of the class to be used while casting, another type in Java 1.3? Is there any way i can class name with the right type string parameter?

What does the casting mean when you give results to all of the objects?

  To make the public: If you do not apply the interface, do not expand or class, or do nothing, you will get an exception. Static Boolean IsInstance (object x, string classname) {class class = class. Formaim (classname); Return cls.isInstance (x); }  

is adequate (and cleaner)

If you use reflection to obtain that field / methods, which is still okay


Comments