I want to re-use a Builder instance to create several controls but I’m getting compile errors which I don’t understand. I think they’re caused by me not understanding generics properly. Can anyone help?
ButtonBuilder builder = ButtonBuilder.create().minHeight(40.0).minWidth(40.0);
Button button1 = builder.onAction(clickHandler).build(); // Error
Button button2 = ButtonBuilder.create().minHeight(40.0).minWidth(40.0).onAction(clickHandler).build(); //OK
where clickHandler is a EventHandler<ActionEvent>
The error I get is
error: cannot find symbol
Button button1 = builder.onAction(clickHandler).build();
^
symbol: method build()
location: class ButtonBaseBuilder
ButtonBaseBuilder implements Builder so it should have a build() method, shouldn’t it? Also if I run everything together (as in button2) it is OK.
This is on JDK 7.0u4 and JavaFX SDK 2.1
Thanks in advance,
Pete
You need to pass ButtonBuilder generic parameter to use builders that way: