You can use the option to avoid NullPointerExceptions.
The following is an example of using this case.
chartControlButtons.add(
new JButton("Zoom In") {{
addActionListener(
(ActionEvent e) -> Optional.ofNullable(getChartController()).ifPresent(s -> s.zoomIn())
);
}}
);
source
share