| | |
problem with reflection
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 71
Reputation:
Solved Threads: 1
haii
I have a problem while accessing a class(A) through "reflection" from class B....
i want to pass a parameter to class A...
My code is like this...
Method idMethod = Class.forName(ClassName).getMethod(FunctionName,null);
Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});
Object object = getMethod.invoke(Class.forName(ClassName()),new Object[]{dboption});
lists = (ArrayList)idMethod.invoke(object,personId);
i will get correct result when the parameter is a String(Like above)...But how can i pass an Object ...
I have a problem while accessing a class(A) through "reflection" from class B....
i want to pass a parameter to class A...
My code is like this...
Method idMethod = Class.forName(ClassName).getMethod(FunctionName,null);
Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});
Object object = getMethod.invoke(Class.forName(ClassName()),new Object[]{dboption});
lists = (ArrayList)idMethod.invoke(object,personId);
i will get correct result when the parameter is a String(Like above)...But how can i pass an Object ...
Which method are you wanting to pass an object to? "idMethod" is getting a no-arg method and "getMethod" is getting this method . If you need Your question is not very clear, so if that is not what you were asking you will need to clarify it a bit more.
getInstance(String) with this line Java Syntax (Toggle Plain Text)
Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});
getInstance(Object) the you need to use Java Syntax (Toggle Plain Text)
Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{java.lang.Object.class});
![]() |
Other Threads in the Java Forum
- Previous Thread: sentinel method - While/For loop
- Next Thread: How to connect Oracle database from JSP page
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes client code component consumer database draw eclipse ee error event exception fractal free game gameprogramming gis givemetehcodez graphics gui helpwithhomework html ide image input integer j2me j2seprojects java javaprojects jmf jni jpanel julia jvm key linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline nls number oracle output print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows






