[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: finding method efficiently

From: David Holmes
Subject: RE: finding method efficiently
Date: Tue, 28 Sep 2004 16:12:01 +1000

> Tom Tromey writes
> >>>>> "Robert" == Robert Schuster <address@hidden> writes:
> Robert> Now when evaluating the XML data I have to search the method "put"
> Robert> which accepts the two arguments. Having
> Robert> only String and JFrame as argument types means that the call to
> Robert>      HashMap.class.getMethod("put", new Class[] { String.class,
> Robert>      JFrame.class });
> Robert> will fail. My current naive approach to find HashMap.put(Object,
> Robert> Object) is to generate a long list of a superclasses and
> Robert> interfaces of all arguments and then calling getMethod("put", ..)
> Robert> with every combination.
> You could use Class.getMethods to get an array of all methods in a
> class, then search for the method that allows this call, by using
> isAssignableFrom on the arguments.  That's about all I can think of.
> This is more efficient than using getMethod since you don't need to
> generate all combinations of the method argument types.  getMethods
> will look at the inheritance tree for you, so you only need to call it
> once.

But first you have to filter out the public methods, as getMethods will
return them all.

Hmmm. There is a further problem that you have to work out how to do this
such that overload resolution is applied correctly. Basically I can't see
any way to do this other than to reapply the same method resolution logic
that javac would use! Find all applicable methods, then find the most

For the XML not to carry the parameter type information seems fundamentally
broken. :(

David Holmes

reply via email to

[Prev in Thread] Current Thread [Next in Thread]