-3

While working on somebodys else code I found some weird construction, which for I couldnt find any explanation on the internet. Here is the whole method from JavaFXML Application:

private void logInUser(User selectedUser) throws IOException {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/movierecsys/gui/view/MovieRecView.fxml"));
    Parent root1 = (Parent) fxmlLoader.load();
    fxmlLoader.<MovieRecController>getController().setInfo(selectedUser);
    Stage stage = (Stage) loginButton.getScene().getWindow();
    stage.setScene(new Scene(root1));
    stage.show();
}

And here is the line which is not really clear for me:

    fxmlLoader.<MovieRecController>getController().setInfo(selectedUser);

What exactly means <MovieRecController> ? It looks like type casting, but i have never met before this construction for casting and I could find any explanation for this.

schemaboi
  • 559
  • 5
  • 9

1 Answers1

-2

It's called a type witness:

The generic method addBox defines one type parameter named U. Generally, a Java compiler can infer the type parameters of a generic method call. Consequently, in most cases, you do not have to specify them. For example, to invoke the generic method addBox, you can specify the type parameter with a type witness as follows:

BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);

Alternatively, if you omit the type witness,a Java compiler automatically infers (from the method's arguments) that the type parameter is Integer:

BoxDemo.addBox(Integer.valueOf(20), listOfIntegerBoxes);
Community
  • 1
  • 1
Andy Turner
  • 137,514
  • 11
  • 162
  • 243