Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to iterate through List returned by method using reflection?

914159Apr 10 2012 — edited Apr 11 2012
Hi,

How do I iterate through the List<Address> and call a method within Address class?

Method m = someObj.getClass().getMethod("listOfIPv4Addresses");
Object aList = m.invoke(someObj); // returns a List<Address>

ParameterizedType returnType = (ParameterizedType) m.getGenericReturnType();
Type[] typeArguments = returnType.getActualTypeArguments();
Class returnTypeParamClass = (Class) typeArguments [0]; // gets the 'Address' Class type

for (Object aAddress : aList) {
// what do i do here?
}

Thanks.
This post has been answered by EJP on Apr 10 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 9 2012
Added on Apr 10 2012
8 comments
1,644 views