Yeah, I know. Long title of question... So I have class name in string. I'm dynamically creating object of that class in this way:
String className = "com.package.MyClass";
Class c = Class.forName(className);
Object obj = c.newInstance();
How I can dynamically convert that **obj** to **MyClass** object? I can't write this way:
MyClass mobj = (MyClass)obj;
...because **className** can be different. That code doesn't convert: it typecasts. Is that what you mean?
以上就是Dynamically converting java object of Object class to a given class when class name is known的详细内容，更多请关注web前端其它相关文章！