User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jan 2008
Posts: 36
Reputation: ajithraj is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ajithraj ajithraj is offline Offline
Light Poster

problem with reflection

  #1  
Apr 10th, 2008
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 ...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,657
Reputation: Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light 
Rep Power: 11
Solved Threads: 262
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: problem with reflection

  #2  
Apr 10th, 2008
Which method are you wanting to pass an object to? "idMethod" is getting a no-arg method and "getMethod" is getting this method getInstance(String) with this line
Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});
. If you need getInstance(Object) the you need to use
Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{java.lang.Object.class});
Your question is not very clear, so if that is not what you were asking you will need to clarify it a bit more.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Java Forum

All times are GMT -4. The time now is 1:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC