Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33512
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: methodhandles lookup |
| Date | 2016-01-22 16:49 +0100 |
| Organization | albasani.net |
| Message-ID | <n7tj2u$f0m$1@news.albasani.net> (permalink) |
| References | <1abadfac-e34b-4ff0-8ba5-613355fa928b@googlegroups.com> |
Hi,
If you know the signature, in the sense of knowing the
classes of the formal parameter, you can call
getDeclaredMethod() [1]
Instead of
getDeclaredMethods()
So in case of your foo example below, to find the argument
less bar() method, call
getDeclaredMethod("bar", new Class[]{})
to find the bar() method with primitive integer type, call
getDeclaredMethod("bar", new Class[]{Integer.TYPE})
Yes caching is a good idea in my opinion.
Bye
[1]
https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getDeclaredMethod%28java.lang.String,%20java.lang.Class...%29
Philipp Kraus schrieb:
> The problem is a class like
> class foo
> {
> public void bar()
> {
> System.out.println("test");
> }
>
> public void bar( int x )
> {
> System.out.println("test " + x);
> }
> }
>
> So my question is, how can I create a dynamic binding
> on method handles depend on the signature?
> And can I cache the method handles / is it a good choice
> of caching all handles?
> In my case I know during runtime the concrete signature
> of the method, "foo/bar" is executed and on this
> time I know all arguments of the method, so I can
> create at this point the binding. How can I do this
> in a fast way?
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-22 00:19 -0800
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 08:57 +0000
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 11:01 +0000
Re: methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-22 03:13 -0800
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 11:43 +0000
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 12:03 +0000
Re: methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-24 01:59 -0800
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 12:16 +0000
Re: methodhandles lookup Jan Burse <janburse@fastmail.fm> - 2016-01-22 17:12 +0100
Re: methodhandles lookup Martin Gregorie <martin@address-in-sig.invalid> - 2016-01-22 11:27 +0000
Re: methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-24 01:56 -0800
Re: methodhandles lookup Jan Burse <janburse@fastmail.fm> - 2016-01-22 16:49 +0100
csiph-web