Is there a way to eliminate reflection on zero argument java constructor calls?
I'm currently passing around an anonymous fn that looks like this:
:listener-ctor #(XListener.) and then it's invoked and used by the caller, but graal can't find it.
I have a multitude of different Listeners and they don't share any meaningful base class unfortunately.
Maybe helping GraalVM along with a reflection.json helps?
{
"name": "foo.bar.XListener",
"queryAllDeclaredConstructors": true,
"queryAllPublicConstructors": true
},What does the Clojure compiler say when you set:
(set! *warn-on-reflection* true)If Clojure doesn't complain, it's maybe a different issue
It does complain 🙂
Then you can likely fix it within Clojure itself without adding reflection config?
Let me double check what it thinks the problem is...
Yes @rahul080327 it does work to do that, and that might be my fallback approach.
yeah eliminating it via a typehint should be nicer
Yeah so the problem I guess is that in the call site we use a .instanceMethod type of call, and that function that looks roughly like this:
(defn ->top-secret
[listener]
(->> listener
.getFunctions
parsed-fns->internal-format
(into [])))*warn-on-reflection* doesn't like that one, but I have 25 different listeners without a common base class to hint against
you can add a type-hint to the listener argument
I might have to pass it the ->top-secret function or a wrapped getFunctions instead I think? because the caller does not have access to my 25 different types of Listener and there's no commonality between them
But I could construct a type-hinted getFunctions wrapper per Listener
maybe 😮
or maybe there can be an interface introduced?
It's generated code so I'm a bit tied up on the java side - but could I do something in clojure?
you can't retrofit an interface to JVM types in Clojure, but you can introduce protocols. You'll have to extend it to your 25 concrete classes though, which doesn't buy you much
All right, thanks so much for the help I'll try to pass something with type hints 🙂
Otherwise I guess I dig into the classes and generate the reflect config
Maybe you fellows know a good programmatic way to access a namespaces' imports? 🙂
(ns-imports *ns*)❤️