tags:

views:

27

answers:

2

i have a method as follows.

test(Object obj){

}

now within this method i want to get all fileds along with the datatypes of those fileds. How can i do that??

+3  A: 

you will need to use reflection. see this link from the Java tutorial.

keep in mind that reflection can be pretty expensive at runtime, so use it wisely.

Omry
A: 

As Omry suggested, you need to use Reflection. Link 1Link 2

Using reflection is very resource intensive, violates almost all OOP principles and should be avoided unless really needed. It can get very nasty when you start accessing private data members/methods and violating the presentation invariants of the objects you're inspecting. Might i suggest using the instanceof operator to find out if your object is of a particular class and going from there?

pnt