1

I am trying to create a generic tableView class, but i want it to handle only the certain data types in my program- which are in a diffrent package.

Is that possible by operating wild cards?

public class  GenericTable <T>{ 

    private Collection<T> data; 

    @FXML
    private Text headline;

    @FXML
    private ObservableList<T> properties=FXCollections.observableArrayList();
    @FXML
    private TableView<T> table;
    @FXML
    private TableColumn<T, String> prop1;
    @FXML
    private TableColumn<T, String> prop2;
    @FXML
    private TableColumn<T, String> prop3;


    public void setData(Collection<T> data){

        this.data=data;
    }

    public void setText(String txt){

        headline=new Text(txt);
    }

    public void initialize(){

    }
}
fantaghirocco
  • 4,761
  • 6
  • 38
  • 48
Loaffer
  • 49
  • 7

1 Answers1

0

Maybe you are looking for Bounded type Parameters.

The extends keyword can be used to restrict the type to be passed as function parameters.

For example the following allows only to be called from anything which either is an instance of the Number class or is an instance of a class which extends the Number class itself:

public <U extends Number> void doSomething(U u) {}

You may want to check also these other SO questions:

Community
  • 1
  • 1
fantaghirocco
  • 4,761
  • 6
  • 38
  • 48