Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33508
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: methodhandles lookup |
| Date | 2016-01-22 11:43 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <n7t4l7$29m$3@dont-email.me> (permalink) |
| References | <1abadfac-e34b-4ff0-8ba5-613355fa928b@googlegroups.com> <n7t26f$29m$2@dont-email.me> <0bf0e18b-b787-4ce2-b0cc-f1706d786127@googlegroups.com> |
On Fri, 22 Jan 2016 03:13:31 -0800, Philipp Kraus wrote:
> Okay thanks.
>
> In my system I have got a component which creates the MethodHandle
> objects from the Method object, so can I create based on the Method
> object the handle object on its signature?
If you can obtain the correct Class<?> from Method you might use one of
the MethodType.methodType(Class<?>, ...) methods. Not sure how fuzzy this
might get when considering such things as bridge or synthetic methods.
> Can you explain how? In my case I will cache all Method objects and
> build the handlers during runtime, is this fast enough?
Fast enough for what?
Not fair answering a question with a question?
Ok then, try it.
>
> Thanks
>
> Phil
>
>
> Am Freitag, 22. Januar 2016 12:04:37 UTC+1 schrieb Jeff Higgins:
>> On Fri, 22 Jan 2016 00:19:07 -0800, Philipp Kraus wrote:
>>
>> > Hello,
>> >
>> > I'm trying to create a flexible (dynamic) binding for method calls
>> > and I have got a problem with overloaded method binding.
>> > In detail: I have created an own programming language which should
>> > call a java method. In my own language I have got grammar constructs
>> > like "foo/bar( "myobject" );". Internal I have got a Map<String,
>> > Object> which maps the string parameter to an object which will be
>> > invoked. foo/bar points to the method, in this case foo is the
>> > classname and bar the method name. So in this example I need a
>> > binding to the method "public void bar();".
>> > My language should also use calls like "foo/bar( "myobject", 1 );".
>> > In this case the Java method "void bar( int x );" should be called.
>> >
>> > The basic invoking call works well, but I overloaded method creates a
>> > problem. If I have got the class
>> >
>> > class foo {
>> > public void bar()
>> > {
>> > System.out.println("test");
>> > }
>> > }
>> >
>> > I do the following:
>> >
>> > final Multimap<String, MethodHandle> y = HashMultimap.create();
>> > for ( final Method x : foo.class.getDeclaredMethods() )
>> > y.put( x.getSimpleName(), MethodHandles.lookup().unreflect(x) );
>> >
>> > This multimap is put to the parser / lexer of my language to resolve
>> > method names but on calling / invoking I get the problem, that I need
>> > the correct methodhandle within the multimap depend on the signature.
>> >
>> > 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?
>>
>> For each MethodHandle examine its MethodType and proceed from there.
>>
>> > 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?
>> >
>> > Thanks
>> >
>> > Phil
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next 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