Skip to content

Commit c0a965a

Browse files
committed
Use switch statement in Snippet62
Makes the code slightly more expressive.
1 parent 4a27cde commit c0a965a

File tree

1 file changed

+7
-7
lines changed
  • examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets

1 file changed

+7
-7
lines changed

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -40,12 +40,12 @@ public static void main (String [] args) {
4040
final Shell shell = new Shell (display);
4141
shell.setText("Snippet 62");
4242
Listener listener = e -> {
43-
String string = "Unknown";
44-
switch (e.type) {
45-
case SWT.MouseDown: string = "DOWN"; break;
46-
case SWT.MouseMove: string = "MOVE"; break;
47-
case SWT.MouseUp: string = "UP"; break;
48-
}
43+
String string = switch (e.type) {
44+
case SWT.MouseDown -> "DOWN";
45+
case SWT.MouseMove -> "MOVE";
46+
case SWT.MouseUp -> "UP";
47+
default -> "Unknown";
48+
};
4949
string +=": button: " + e.button + ", ";
5050
string += "stateMask=0x" + Integer.toHexString (e.stateMask) + stateMask (e.stateMask) + ", x=" + e.x + ", y=" + e.y;
5151
if ((e.stateMask & SWT.BUTTON1) != 0) string += " BUTTON1";

0 commit comments

Comments
 (0)