0

I have an application on JavaFX. In this application, I need to implement, the editor of the column. In the old version of the code worked perfectly:

myColumn.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<MyRowDataObject, String>>() {
                    @Override
                    public void handle(TableColumn.CellEditEvent<MyRowDataObject, String> t) {
                        ((MyRowDataObject) t.getTableView().getItems().get(
                                t.getTablePosition().getRow())
                        ).setFirstName(t.getNewValue());
                    }
                }
);

but when I tried to rewrite the code using the lambda

myColumn.setOnEditCommit((TableColumn.CellEditEvent event) ->
                ((MyRowDataObject) event.getTableView().getItems().get(event.getTablePosition().getRow())).setEmail(event.getNewValue().toString())
);

I get an error :Error: java: incompatible types: incompatible parameter types in lambda expression Tell me how to specify the type of a lambda expression?

5
  • 2
    Have you tried specifying the full generic type as the parameter for the lambda expression, instead of the raw type as you've got it now? Commented Jan 3, 2015 at 21:39
  • 2
    Your problem is the raw type CellEditEvent; if you're going to use a manifest type, make it a full generic type. But you may be able to elide the type completely and let the compiler infer it. Commented Jan 3, 2015 at 21:42
  • italic bold myColumn.setOnEditCommit((TableColumn.CellEditEvent<MyRowDataObject, String> event) -> ((MyRowDataObject)event.getTableView().getItems().get(event.getTablePosition().getRow())).setEmail(event.getNewValue().toString()) );</code> is not work - incompatible parameter types in lambda expression Commented Jan 3, 2015 at 21:49
  • If I do not specify the type of the parameter, the compiler indicates an error:java: cannot find symbol symbol: method getNewValue() location: variable event of type javafx.event.Event Commented Jan 3, 2015 at 22:01
  • Do you mean 'anonymous'? Commented Jan 4, 2015 at 0:12

1 Answer 1

2

Maybe someone will be interested, turned to compile the code as follows.

 myColumn.setOnEditCommit(event -> {
                final TableColumn.CellEditEvent _evn = (TableColumn.CellEditEvent) event;
                ((MyRowDataObject) _evn.getTableView().getItems().get(_evn.getTablePosition().getRow())).setEmail(_evn.getNewValue().toString());
            });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.