beginners

Santiago Cabrera 2025-08-03T15:49:34.987979Z

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?

p-himik 2025-08-03T15:53:01.695259Z

Should should work, with or without java.util.Arrays/asList. What's the symptom of it not working?

Santiago Cabrera 2025-08-03T15:53:34.174229Z

No matching ctor found for class javafx.scene.paint.RadialGradient

Santiago Cabrera 2025-08-03T15:53:58.103289Z

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

Santiago Cabrera 2025-08-03T15:54:39.339479Z

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"}
        }}

p-himik 2025-08-03T16:00:14.770999Z

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.

p-himik 2025-08-03T16:02:34.479509Z

Wait, what the hell. I just refreshed the page and it changed to > For JavaFX 24.0.2, JDK 22 or later is required.

Santiago Cabrera 2025-08-03T16:02:53.206009Z

It should be the same problem with version "19.0.2.1". That's the one morse uses

p-himik 2025-08-03T16:05:36.854029Z

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))

p-himik 2025-08-03T16:08:48.543539Z

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.

Santiago Cabrera 2025-08-03T16:09:16.547619Z

Hmmmm that's weird, I expected it to parse the number to double automatically

p-himik 2025-08-03T16:09:29.478499Z

0 is Long, 0. is Double.

Santiago Cabrera 2025-08-03T16:09:39.347969Z

Thanks! I was so focused on the array that the doubles didn't come to mind