-
Notifications
You must be signed in to change notification settings - Fork 190
Open
Description
I suggest to implement the java.lang.AutoCloseable interface in org.eclipse.swt.graphics.GC so that the try-with-resources Java feature can be used.
Here a concrete example in org.eclipse.jface.dialogs.Dialog where the GC class is used.
protected void initializeDialogUnits(Control control) {
// Compute and store a font metric
GC gc = new GC(control);
gc.setFont(JFaceResources.getDialogFont());
fontMetrics = gc.getFontMetrics();
gc.dispose();
}
gc.dispose() is not called when JFaceResources.getDialogFont() throws an exception.
Wouldn't it be much nicer if the try-with-resource approach would be used here:
protected void initializeDialogUnits(Control control) {
// Compute and store a font metric
try (GC gc = new GC(control)) {
gc.setFont(JFaceResources.getDialogFont());
fontMetrics = gc.getFontMetrics();
}
}
Did you already discuss this topic? Are there any drawbacks of implementing the AutoCloseable interface in GC?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels