| Author |
help with reflection
|
Marco Vanoli
Ranch Hand
Joined: Jan 12, 2005
Posts: 99
|
|
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
|
bye, <br />Marco
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
|
The java.beans.Introspector class does exactly what you need. It provides all the information in a nicely structured way.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Marco Vanoli
Ranch Hand
Joined: Jan 12, 2005
Posts: 99
|
|
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
Joined: Oct 25, 2000
Posts: 7292
|
|
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.
|
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
|
 |
Marco Vanoli
Ranch Hand
Joined: Jan 12, 2005
Posts: 99
|
|
Nice , i do it Is it ok? It seems to work .. Thank you very much!
|
 |
Michael Ernest
High Plains Drifter
Sheriff
Joined: Oct 25, 2000
Posts: 7292
|
|
Nicely done; nothing to it.
|
 |
 |
|
|
subject: help with reflection
|
|
|