Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 439
Markus Paul Avatar asked Jun 25 '15 20:06

Markus Paul


People also ask

What is unchecked warning?

An unchecked warning tells a programmer that a cast may cause a program to throw an exception somewhere else. Suppressing the warning with @SuppressWarnings("unchecked") tells the compiler that the programmer believes the code to be safe and won't cause unexpected exceptions.

What does the compiler mean by an unchecked call?

The warning tells you that the compiler has encountered a condition that it can't guarantee the sense of. You should avoid having this kind of thing.

What is unchecked assignment in Java?

Unchecked assignment: 'java.util.List' to 'java.util.List<java.lang.String>' It means that you try to assign not type safe object to a type safe variable. If you are make sure that such assignment is type safe, you can disable the warning using @SuppressWarnings annotation, as in the following examples.


1 Answers

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.

like image 99
James_D Avatar answered Sep 21 '22 13:09

James_D