A lot of JavaFx methods take var args, such as Group, which is declared in Java as:
public Group(Node... children)
Others for example:
public KeyFrame(Duration time, KeyValue... values)
I've discovered the ...
means I should pass a java array to the method, so I've been doing stuff like this,
(-> timeline .getKeyFrames
(.addAll
(into-array [(KeyFrame. blabla) (KeyFrame. blabla)]))`
It's annoying to have to do (into-array...)
every time there is a var arg, and it's more annoying when the var arg is a base class of what I'm actually passing in. For example
(Group. (into-array [(Circle. 100) (Rectangle. 100 100)]))
results in type mismatch error. Instead I have to do this:
(Group. (into-array Node [(Circle. 100) (Rectangle. 100 100)]))
So i made this function:
(defn make-group [& items]
(Group. (into-array Node items)))
which is fine for Groups, but doesn't solve the general problem.
So is there a nice way of solving the ellipses/vararg problem so I don't have to make special functions for each vararg method? The requirements for this function would be that it take the method you want to call (eg Group
), the fixed args, the var args, and somehow magically the function would know to find the common base class of the elements in the var args.
Thanks