This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-26
Channels
- # announcements (2)
- # asami (2)
- # aws (34)
- # babashka (6)
- # beginners (9)
- # calva (76)
- # chlorine-clover (10)
- # circleci (5)
- # clj-kondo (2)
- # clojure (40)
- # clojure-australia (3)
- # clojure-europe (15)
- # clojurescript (39)
- # conjure (1)
- # core-async (4)
- # cursive (4)
- # datahike (1)
- # datomic (69)
- # figwheel-main (1)
- # graalvm (16)
- # honeysql (9)
- # hyperfiddle (2)
- # jobs-discuss (2)
- # lsp (36)
- # luminus (1)
- # malli (11)
- # off-topic (13)
- # pathom (1)
- # portal (1)
- # portkey (3)
- # reitit (25)
- # reveal (1)
- # rewrite-clj (5)
- # spacemacs (2)
- # sql (4)
- # vrac (90)
I need to extend a Java class, and I’ve been using proxy
to do this. This compiles to native, but then using the object gives me “No matching field found” for the function that I’ve overridden.
I’m thinking that using proxy
may not be allowed when compiling to native, since it’s dynamically creating the class at runtime. Is that right? If so, then I’m thinking that the best approach is to use gen-class
to create this class statically. Or am I missing something that’s easier?
I hope not. Do you have warn-on-reflection true?
Proxy should work since it creates a class file on macroexpansion
I think it should work if you can declare the resulting generated class in the reflection config
Also, there is the proxy config on graalvm, for lsp4j on clojure-lsp I needed to declare these classes on proxy config. Ref: https://github.com/clojure-lsp/clojure-lsp/blob/master/resources/META-INF/native-image/clojure-lsp/clojure-lsp/proxy-config.json#L2
As for proxy
, it appears that calling proxy-super
will try to call the method on the superclass, but it attempts to reflect to find it
What I’m trying to do is to create a PushbackReader
that returns a 0
when it encounters a ;
character.
This works when it’s run in the JVM:
(proxy [PushbackReader] [reader-input]
(read [] (let [c (proxy-super read)]
(if (= (int \;) c)
0
c))))
Instead, I did it with this:
(gen-class
:name "asami.PBR"
:extends java.io.PushbackReader
:prefix "pbr-"
:exposes-methods {read readSuper})
(defn pbr-read
[this]
(let [c (.readSuper ^asami.PBR this)]
(if (= (int \;) c)
0
c)))
Then, instead of returning a proxy, I just instantiated it:
(asami.PBR. reader-input)