public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Per Bothner <per@bothner.com>
To: Sonny To <son.c.to@gmail.com>, Kawa mailing list <kawa@sourceware.org>
Subject: Re: using lambda to implement one method interface
Date: Sun, 17 Sep 2017 15:59:00 -0000	[thread overview]
Message-ID: <d3a88010-0cca-4630-6014-4d26ee4a33c2@bothner.com> (raw)
In-Reply-To: <CAJxjsJvoUdTSDrz-n9JwZZ1vhhoDx2inp0+975e+3WF1yv5Vpg@mail.gmail.com>

On 09/17/2017 08:38 AM, Sonny To wrote:
> this works
> 
> (let ((handler (android.os.Handler (android.os.Looper:getMainLooper)))
>        )
>    (handler:post (lambda ()
>                          (android.util.Log:i "scm" "run me")))
>    )
> 
> this is non-intuitive. why doesn't it work if i bind the lambda to a
> symbol? seems like a bug to me

Perhaps a documentation bug: It may not be clear that when the manual
say "required type" in:

     This is possible when the required type is an interface or
     abstract class with a Single (exactly one) Abstract Methods.

we mean the type required by the *compile-time context* of the expression.

This is a deliberate design limitation, not a bug.  This way the anonymous
class can be created a compile-time, not run-time.  Doing it at run-time
would be more difficult and more expensive. Kawa has always put a high
priority on performance.

Perhaps a future Kawa extension will allow "SAM-conversion" at run-time,
but it is not currently in the plans.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

  reply	other threads:[~2017-09-17 15:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-17 15:32 Sonny To
2017-09-17 15:38 ` Sonny To
2017-09-17 15:59   ` Per Bothner [this message]
2017-09-17 16:04     ` Sonny To
2017-09-17 16:50       ` Per Bothner
2017-09-17 18:54         ` Sonny To
2017-09-17 20:02           ` Per Bothner
2017-09-18  6:35             ` Sonny To
2017-09-18  8:17               ` Sonny To
2017-09-18 13:59                 ` Per Bothner
2017-09-18 11:22               ` Sudarshan S Chawathe
2017-09-18 14:24                 ` Per Bothner
2017-09-18 14:31                   ` Sudarshan S Chawathe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d3a88010-0cca-4630-6014-4d26ee4a33c2@bothner.com \
    --to=per@bothner.com \
    --cc=kawa@sourceware.org \
    --cc=son.c.to@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).