Hi, how can I call create a java object with a varargs constructor and another one that is the same but the last parameter is a list?
(import javafx.stage.Stage
javafx.scene.Group
javafx.scene.Scene
javafx.scene.shape.Ellipse
javafx.scene.paint.RadialGradient
javafx.scene.paint.CycleMethod
javafx.scene.paint.Stop
javafx.scene.paint.Color
)
(let [focus-angle 0
focus-distance 0.1
center-x 80
center-y 45
radius 180
proportional? false
cycle-method CycleMethod/NO_CYCLE
stops (java.util.Arrays/asList (into-array Stop [(Stop. 0 Color/RED) (Stop. 1 Color/BLACK)]))
]
(RadialGradient. focus-angle focus-distance center-x center-y radius proportional?
cycle-method stops ))
I can't create this javafx object, I tried with an array, a list, adding param-tags metadata. How can I do this?Should should work, with or without java.util.Arrays/asList.
What's the symptom of it not working?
No matching ctor found for class javafx.scene.paint.RadialGradient
And in the editor it says Cannot disambiguate overloads of javafx.scene.paint.RadialGradient constructor: (RadialGradient. ^double v ^double v1 ^double v2 ^double v3 ^double v4 ^boolean b ^CycleMethod cycleMethod ^Stop... stops) (RadialGradient. ^double v ^double v1 ^double v2 ^double v3 ^double v4 ^boolean b ^CycleMethod cycleMethod ^List<Stop> list
You can try it out in the REPL with these deps
{:deps {org.clojure/clojure {:mvn/version "1.12.1"}
org.openjfx/javafx-fxml {:mvn/version "24.0.2"}
org.openjfx/javafx-controls {:mvn/version "24.0.2"}
org.openjfx/javafx-swing {:mvn/version "24.0.2"}
org.openjfx/javafx-base {:mvn/version "24.0.2"}
org.openjfx/javafx-web {:mvn/version "24.0.2"}
}}
Execution error (UnsupportedClassVersionError) at java.lang.ClassLoader/defineClass1 (ClassLoader.java:-2).
javafx/stage/Stage has been compiled by a more recent version of the Java Runtime (class file version 66.0), this version of the Java Runtime only recognizes class file versions up to 65.0
sigh Why do people do this...
> For JavaFX 24, JDK 21 or later is required
I have JDK 21, class file version 65 is JDK 21. Bloody hell.Wait, what the hell. I just refreshed the page and it changed to > For JavaFX 24.0.2, JDK 22 or later is required.
It should be the same problem with version "19.0.2.1". That's the one morse uses
Right. I had a suspicion but decided to check it before writing anything - you gotta use explicit double values instead of longs. Also, Clojure vectors are Lists already.
(let [focus-angle 0.
focus-distance 0.1
center-x 80.
center-y 45.
radius 180.
proportional? false
cycle-method CycleMethod/NO_CYCLE
stops [(Stop. 0 Color/RED) (Stop. 1 Color/BLACK)]]
(RadialGradient. focus-angle focus-distance
center-x center-y
radius proportional? cycle-method
stops))BTW the "Cannot disambiguate overloads" message from the editor (Cursive?) is a red herring. It doesn't mean that Clojure doesn't know what to do. Or even that it'll have to use reflection. It just means that Cursive can't figure out what's what.
Hmmmm that's weird, I expected it to parse the number to double automatically
0 is Long, 0. is Double.
Thanks! I was so focused on the array that the doubles didn't come to mind