From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from MTA-08-3.privateemail.com (mta-08-3.privateemail.com [198.54.127.61]) by sourceware.org (Postfix) with ESMTPS id 7D4FD3858D34 for ; Mon, 30 Aug 2021 23:19:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7D4FD3858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eatonphil.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eatonphil.com Received: from mta-08.privateemail.com (localhost [127.0.0.1]) by mta-08.privateemail.com (Postfix) with ESMTP id 72D2118006CE for ; Mon, 30 Aug 2021 19:19:03 -0400 (EDT) Received: from mail-ua1-f43.google.com (unknown [10.20.151.230]) by mta-08.privateemail.com (Postfix) with ESMTPA id 5903618001AA for ; Mon, 30 Aug 2021 19:19:03 -0400 (EDT) Received: by mail-ua1-f43.google.com with SMTP id g2so8733379uad.4 for ; Mon, 30 Aug 2021 16:19:03 -0700 (PDT) X-Gm-Message-State: AOAM530ziJFA+4+QsN2wKlHuaEMFEJ+H4Sah4twsyBhhDb2gcBob4Y7L jdbGNqiuCP4VHnGkAfzxtx5bn2H/+Bd2tNXdYLo= X-Google-Smtp-Source: ABdhPJxYXq58ZN2xz4vcmXm3sus3WabcNONcIUTy1bNAhvm+FsnmU6+Y73EaYvOh5UwG73RklyxfhLsh6Y2XdrKyCaY= X-Received: by 2002:ab0:413:: with SMTP id 19mr16622887uav.38.1630365542303; Mon, 30 Aug 2021 16:19:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Phil Eaton Date: Mon, 30 Aug 2021 19:18:52 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Receiver class does not define or inherit an implementation of the resolved method To: Per Bothner Cc: kawa mailing list X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, HTML_MESSAGE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: kawa@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Kawa mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2021 23:19:14 -0000 I spoke too soon. The issue is that I truly do need both of these methods to be called `apply` not `apply` and `apply$1`. For what it's worth this kind of redefinition of the same method worked for me in ABCL lisp. So I know it's definitely possible to express in Java. On Mon, Aug 30, 2021 at 7:09 PM Phil Eaton wrote: > Aha! It gave my second apply method a different suffix. By reordering > these two methods the whole thing somehow works. > > $ javap main\$0.class > Compiled from "main.scm" > public class main$0 implements io.jooby.Route$Handler { > main$frame this$0; > public java.lang.CharSequence apply(io.jooby.Context); > public java.lang.Object apply$1(io.jooby.Context); > public main$0(main$frame); > } > > > It's weird but I'll take it. > > > > On Mon, Aug 30, 2021 at 12:40 PM Per Bothner wrote: > >> On 8/29/21 12:03 PM, Phil Eaton wrote:> Still new to Kawa. I'm trying to >> implement an interface ( >> > io.jooby.Route$Handler >> > < >> https://github.com/jooby-project/jooby/blob/2.x/jooby/src/main/java/io/jooby/Route.java#L247 >> >). >> > It only has a single non-default method, apply. >> > >> > Here's what I've got >> > >> > (define (route app method path handler) >> > (let ((handler (object (io.jooby.Route$Handler) >> > #| This method exists just to stop Jooby from >> > trying to introspect Java code that doesn't exist because this isn't >> > written in Java. |# >> > ((apply (ctx ::io.jooby.Context)) ::string >> > #!null) >> > ((apply (ctx ::io.jooby.Context)) >> > ::java.lang.Object >> > (handler ctx))))) >> > (app:route method path handler))) >> > >> > >> > But when this gets exercised, I get: >> > >> > [worker-1-3] ERROR io.jooby.Jooby - GET /hello-world 500 Server Error >> > java.lang.AbstractMethodError: Receiver class main$0 does not define or >> > inherit an implementation of the resolved method 'abstract >> java.lang.Object >> > apply(io.jooby.Context)' of interface io.jooby.Route$Handler. >> >> I don't see anything obviously wrong. One thing to try is instead of an >> anonymous class (with object) use a named class (with >> define-simple-class). >> The anonymous class is more convenient of course there is some extra >> "magic" >> (such as invisible fields) that might complicate things. >> >> > Also on a tangent, I was excited about the lambda shorthand for single >> > method objects. Like I said this interface only has a single non-default >> > method: apply. But I tried just calling `(app:route method handler)` >> > without wrapping it in the io.jooby.Route$Handler object but it still >> > failed. I guess it couldn't figure out this one method. >> >> Kawa has to be able to figure out at compile time that a specific >> class/interface >> is required before it can convert the lambda to an object. (As far as I >> can >> remember, doing this conversion at run-time isn't implemented, and would >> be >> fairly complicated.) So you may need to add some more type-specifiers. >> >> I suggest using javap to look at the generated classes, to see what is >> going on. >> -- >> --Per Bothner >> per@bothner.com http://per.bothner.com/ >> >