• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with reflection

 
Marco Vanoli
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a javabean;
in my program i have to analyze the bean , then put in a list all properties name (String) that have a set method and also a get method. (some properties could have only get or set method).

What can i use to do this work..??

I thinked to use the java.lang.reflect showMethods(bean) but i have to parse all stings and make checks for get and set.. it is cumbersome.

Isn' t there a quickest pratice to do this?
tnk
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.beans.Introspector class does exactly what you need. It provides all the information in a nicely structured way.
 
Marco Vanoli
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes think this is the right way but no example ho to use it

can somebody gimme an example of how to use Introspector on a bean to show its properies?

tnk
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Introspector's getBeanInfo() method and provide the class that has your bean properties as an argument. This method returns a BeanInfo object which will then return a list of properties from the class.

The challenge to you is to try it; post your code here for review if you like. More than happy to help you with code that isn't quite doing what you want.
 
Marco Vanoli
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice , i do it


Is it ok? It seems to work ..

Thank you very much!
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Nicely done; nothing to it.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic