S
Sébastien de Mapias
Hi,
Once I've retrieved the methods of a class using reflection,
I find the following for example:
~ method.getName(): "getTickets"
~ method.getGenericReturnType():
"java.util.List<com.my.project.stuff.Ticket>"
~ method.getReturnType(): "interface java.util.List"
Now I'd like to access the list of Tickets I have and run against
each
of them the 'getDeclaredMethods()' to invoke their methods, one after
each other.
But when passing "method.invoke(myObj, (Object[])null)", i.e. when
invoking 'getTickets(), and passing the returned object to my
procedure
that does the job, then when I execute again the following
~ Class<?> klass = Class.forName(myObj.getClass().getName());
~ Method[] methods = klass.getDeclaredMethods();
and loop through the methods, I get those of java.util.List of course
('trimToSize', 'ensureCapacity'...).
My procedure is recursive (I want to traverse a series of objects in
cascade,
get at their methods, retrieve references...).
This is not what I want: I want to access every method of Ticket
(getFare(),
getReduction() etc.) *inside* of my java.util.List.
Is there a way to nicely do this ? (I mean rather than tokenizing my
array
of [com.my...Ticket@67546754, com.my...Ticket@87638493, ...] and
looping
through these string references)
Thanks a lot !
Best regards,
Sébastien
Once I've retrieved the methods of a class using reflection,
I find the following for example:
~ method.getName(): "getTickets"
~ method.getGenericReturnType():
"java.util.List<com.my.project.stuff.Ticket>"
~ method.getReturnType(): "interface java.util.List"
Now I'd like to access the list of Tickets I have and run against
each
of them the 'getDeclaredMethods()' to invoke their methods, one after
each other.
But when passing "method.invoke(myObj, (Object[])null)", i.e. when
invoking 'getTickets(), and passing the returned object to my
procedure
that does the job, then when I execute again the following
~ Class<?> klass = Class.forName(myObj.getClass().getName());
~ Method[] methods = klass.getDeclaredMethods();
and loop through the methods, I get those of java.util.List of course
('trimToSize', 'ensureCapacity'...).
My procedure is recursive (I want to traverse a series of objects in
cascade,
get at their methods, retrieve references...).
This is not what I want: I want to access every method of Ticket
(getFare(),
getReduction() etc.) *inside* of my java.util.List.
Is there a way to nicely do this ? (I mean rather than tokenizing my
array
of [com.my...Ticket@67546754, com.my...Ticket@87638493, ...] and
looping
through these string references)
Thanks a lot !
Best regards,
Sébastien