aspose file tools*
The moose likes Java in General and the fly likes trouble with reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "trouble with reflection" Watch "trouble with reflection" New topic
Author

trouble with reflection

anitha nair
Greenhorn

Joined: Jul 12, 2006
Posts: 12
Hi forum,

Please help me out with this problem.

I am getting the parameter types of a method in a class as

Class[] parameterTypes=method.getPrameterTypes();

I need to test if the parameter types are of primitive types i.e int or String or long etc...If its not it should show a message box.
For that i used the following code.The trouble is that it doesnt seems to test the whole conditions.It seems to check only the first condition and for all other conditions it gives a negative result.i.e for String,long,float etc it shows the message box whereas it should be executing else condition instead.Please tell me whats wrong with it.



Thank you all in advance.
[ August 08, 2006: Message edited by: Bear Bibeault ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41808
    
  62
Are you sure that Class.toString returns the result you're expecting? toString returns a string representation, but not necessarily the one you would expect. Try the getName method instead. Also, don't call it 9 times - call it once, and store the result in a variable.


Ping & DNS - my free Android networking tools app
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

It would seem much better to test the class of the arguments rather than the class name. You can then simplify the problem to checking if the class of the parameters is in an allowable set. For example -


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

I have just updated teh code so theat it woll work with Java prior to 1.5.

Singhal Anuj
Greenhorn

Joined: Mar 28, 2005
Posts: 8
Hi,

I do not think this code will compile in java 1.4

Regards,
Anuj
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3527
    
  15
Originally posted by anitha nair:

I need to test if the parameter types are of primitive types i.e int or String or long etc...


Just for the record, String is not a primitive type.


Joanne
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Probably a waste of time since the OP did not seem interested but ...



[ August 08, 2006: Message edited by: James Sabre ]
[ August 08, 2006: Message edited by: James Sabre ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trouble with reflection