Java Reflection – A dummies question

My question is pretty simple – how does one figure out given a method name what the parametypes are?

The only way that I can think of using reflection is as follows

Class cls = Class.forName("com.reporting.beans.AssetBean");
Method meth[];
meth = cls.getDeclaredMethods();
Class[] parameterTypes = meth[o].getParameterTypes()

Are there are any other ways ?

Advertisements

2 thoughts on “Java Reflection – A dummies question”

  1. Well, you could parse the raw class file yourself, but other than that I think reflection’s your only choice. That’s what it’s there for.

    Of course, don’t forget that there may be multiple methods with that name (overloaded), so there may not be a unique list of parameters.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s