This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: using lambda to implement one method interface


It seems implementing single method interface using lambda only works
with methods and not in constructors?

for example, this fails

#|kawa:137|# (java.lang.Thread (lambda ()
                    (+ 1 1)))
#|.....138|# /dev/stdin:137:1: warning - no possibly applicable method
'<init>/valueOf' in java.lang.Thread
gnu.mapping.WrongArguments
        at gnu.mapping.MethodProc.matchFailAsException(MethodProc.java:136)
        at gnu.kawa.reflect.Invoke.applyToObject(Invoke.java:264)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at gnu.mapping.CallContext$ReflectMethodHandle.invokeExact(CallContext.java:726)
        at gnu.mapping.Procedure.applyToConsumerDefault(Procedure.java:75)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at gnu.mapping.CallContext$ReflectMethodHandle.invokeExact(CallContext.java:726)
        at gnu.mapping.CallContext.runUntilDone(CallContext.java:586)
        at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:342)
        at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211)
        at kawa.Shell.run(Shell.java:283)
        at kawa.Shell.run(Shell.java:196)
        at kawa.Shell.run(Shell.java:183)
        at kawa.repl.processArgs(repl.java:714)
        at kawa.repl.main(repl.java:820)

On Mon, Sep 18, 2017 at 9:35 AM, Sonny To <son.c.to@gmail.com> wrote:
> yes that was an error. copy and paste of testing code.  how would I
> implement an interface with multiple methods?
>
>
> On Sun, Sep 17, 2017 at 11:02 PM Per Bothner <per@bothner.com> wrote:
>>
>> On 09/17/2017 11:54 AM, Sonny To wrote:
>> > this is a big problem for my use case...
>> >
>> > i wouldn't be able to do something like this on android at runtime
>> >
>> > (object (java.lang.Runnable)
>> > ((run (a ::void))::void
>> >           (+ 1 1)
>> >           ))
>>
>> You can probably work around it with:
>>
>> (->java.lang.Runnable
>>    (lambda ()::void (set! i (+ i 1))))
>>
>> BTW - I assume (a ::void) is just a typo.  Kawa should probably complain
>> about it.
>> --
>>         --Per Bothner
>> per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]