• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

trouble with reflection

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 -
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have just updated teh code so theat it woll work with Java prior to 1.5.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I do not think this code will compile in java 1.4

Regards,
Anuj
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic