•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 401,466 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,057 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 323 | Replies: 1 | Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 0
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 Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});getInstance(Object) the you need to use Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{java.lang.Object.class});![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Java Forum
- Previous Thread: sentinel method - While/For loop
- Next Thread: How to connect Oracle database from JSP page



Linear Mode