0

I am relatively new to JavaFX. I have chosen the game "BrickBreaker", which is included as an example in NetBeans, to help me understand JavaFX.

The following code is from class Splash:

KeyFrame kf = new KeyFrame(Config.ANIMATION_TIME, new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {

           //some code …
        });

My question is: is it possible to instantiate a KeyFrame without passing any instance of KeyValue to its constructor ?

The documentation shows five versions of the constructor HERE, and they all have a KeyValue argument, while the above code does not.

  • 1
    what happened when you tried :) – kleopatra Oct 19 '19 at 08:29
  • @kleopatra the game is working perfectly. But my question remains. As a developer, the documentation should be my #1 reference. Check the link in my question, no match to the constructor used in the code snippet. confusing, right ?! –  Oct 19 '19 at 08:50
  • 1
    Related: [Java, 3 dots in parameters](https://stackoverflow.com/questions/3158730). Four of the five constructors use `KeyValue...` which is a _varargs_ parameter. The constructor call in your example passes a `Duration`, `EventHandler`, and a `KeyValue[]` of length `0` as arguments. – Slaw Oct 19 '19 at 08:50
  • Indeed it's completely fine to not pass any values to a varargs parameter. The constructor your code uses is this one: https://openjfx.io/javadoc/12/javafx.graphics/javafx/animation/KeyFrame.html#%3Cinit%3E(javafx.util.Duration,javafx.event.EventHandler,javafx.animation.KeyValue...) (note that many IDEs provide info about the signature of the method/constructor invoked; this could be used to your advantage, if you're unsure about things like this.) – fabian Oct 19 '19 at 08:53
  • as developers, we should refresh our basic language knowledge regularly :) – kleopatra Oct 19 '19 at 09:01
  • @kleopatra I think we both (me & you) just did :) –  Oct 19 '19 at 09:18

1 Answers1

1

For the benefit of all those looking for an answer to this question, and to make this question appear as answered in searches, I am answering my own question by quoting SLAW comment:

Related: Java, 3 dots in parameters. Four of the five constructors use KeyValue... which is a varargs parameter. The constructor call in your example passes a Duration, EventHandler, and a KeyValue[] of length 0 as arguments.