Search code examples
javagenericsjavafxwarningsunchecked

How do i get rid of these (unchecked call) warnings?


warning: [unchecked] unchecked call to setCellValueFactory(Callback<CellDataFeatures<S,T>,ObservableValue<T>>) as a member of the raw type TableColumn column1.setCellValueFactory(new PropertyValueFactory<String, State>("name"));   where S,T are type-variables:
    S extends Object declared in class TableColumn
    T extends Object declared in class TableColumn

code:

column1.setCellValueFactory(new PropertyValueFactory<>("name"));

warning: [unchecked] unchecked call to add(E) as a member of the raw type List
            transitionTable.getColumns().add(column1);
  where E is a type-variable:
    E extends Object declared in interface List

code:

transitionTable.getColumns().add(column1);

warning: [unchecked] unchecked call to setAll(Collection<? extends E>) as a member of the raw type ObservableList
        automatonSelection.getItems().setAll(automatonManager.getMachines());
  where E is a type-variable:
    E extends Object declared in interface ObservableList

code:

automatonSelection.getItems().setAll(automatonManager.getMachines());

automatonSelection is a ComboBox and getMachines() returns a LinkedList of the type Automaton


warning: [unchecked] unchecked call to addListener(ChangeListener<? super T>) as a member of the raw type ObservableValue
        automatonSelection.valueProperty().addListener((ObservableValue observable,
  where T is a type-variable:
    T extends Object declared in interface ObservableValue

code:

automatonSelection.valueProperty().addListener((ObservableValue observable,
            Object oldValue, Object newValue) -> {
        stateChanged();
    });

I tried to fix most of those warnings and managed to do so by adding generics, but I can't see how to fix those other 4 warnings.


Solution

  • Don't declare your TableViews and TableColumns as raw types.

    In other words, instead of

    TableView personTable ;
    TableColumn firstNameColumn ;
    

    use

    TableView<Person> personTable ;
    TableColumn<Person, String> firstNameColumn ;
    

    etc.

    Don't suppress these warnings, they will help you debug problems.