【问题标题】:How do i get rid of these (unchecked call) warnings?我如何摆脱这些(未经检查的呼叫)警告?
【发布时间】:2015-06-25 20:36:14
【问题描述】:
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

代码:

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

代码:

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

代码:

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

automatonSelection 是一个 ComboBox,getMachines() 返回一个 Automaton 类型的 LinkedList


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

代码:

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

我尝试修复大部分警告,并通过添加泛型设法解决了问题,但我不知道如何修复其他 4 个警告。

【问题讨论】:

标签: java generics javafx warnings unchecked


【解决方案1】:

不要将您的 TableViews 和 TableColumns 声明为原始类型。

换句话说,而不是

TableView personTable ;
TableColumn firstNameColumn ;

使用

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

等等

不要隐藏这些警告,它们会帮助您调试问题。

【讨论】:

  • 我完全像这样声明了我的专栏,但仍然收到警告
  • 您使用的是 Java 8 吗?对于transitionTable.getColumns().add(column1);,如果transitionTablecolumn1 是这样声明的,您将无法收到警告。
  • 我设法修复了这些警告,但最后两个仍然存在,你能帮忙吗?尤其是有听众的那个
  • 您能出示automatonSelection 的声明吗?你应该有ComboBox&lt;Something&gt; automatonSelection ... ;automatonSelection.valueProperty().addListener((ObservableValue&lt;Something&gt; observable, Something oldValue, Something newValue) -&gt; ...);
猜你喜欢
  • 2017-01-25
  • 2018-10-10
  • 2015-06-22
  • 1970-01-01
  • 2020-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多