0

There are 2 classes: PipeCable and Pipe which extends PipeCable.

I have a TableView: private TableView<PipeCable> workshopList;

And I'd like to add to this TableView an ObservableList of Pipes:

private ObservableList<Pipe> pipeList;

I try to add this list to TableView:

workshopList.setItems(data.getPipeList());

But I get error:

The method setItems(ObservableList< PipeCable >) in the type TableView < PipeCable > is not applicable for the arguments (ObservableList< Pipe >)

What am I doing wrong?

Michael
  • 41,989
  • 11
  • 82
  • 128
miki
  • 83
  • 2
  • 14
  • Either add an `ObservableList` (these could actually be `Pipe` instances) or make the table `TableView`. – Michael Apr 03 '17 at 10:59
  • 1
    See ["Is List a subclass of List?"](http://stackoverflow.com/questions/2745265/is-listdog-a-subclass-of-listanimal-why-arent-javas-generics-implicitly-p) – Michael Apr 03 '17 at 10:59

1 Answers1

0

You defined workshopList with the generic type PipeCable. So the signature is setItems(ObservableList<PipeCable>) and you cannot invoke this method with an ObservableList<Pipe>. Create your field as private TableView<Pipe> workshopList.

Stefan Warminski
  • 1,845
  • 1
  • 9
  • 18
  • Then i will not be able to display both Cables and Pipes in one TableView. – miki Apr 03 '17 at 11:14
  • I don't know your `data` but maybe you can change it's return type of `getPipeList` to `ObservableList`. This list may also contain `Pipe`s... – Stefan Warminski Apr 03 '17 at 11:23