From c8087897ab2cacdb9a2bff65a7dd58e5ee266e89 Mon Sep 17 00:00:00 2001 From: Aleksandar Kurtakov Date: Wed, 9 Jul 2025 17:18:30 +0300 Subject: [PATCH] Use switch statement in Snippet62 Makes the code slightly more expressive. --- .../src/org/eclipse/swt/snippets/Snippet62.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java index ee913cebe98..d13d819e163 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -40,12 +40,12 @@ public static void main (String [] args) { final Shell shell = new Shell (display); shell.setText("Snippet 62"); Listener listener = e -> { - String string = "Unknown"; - switch (e.type) { - case SWT.MouseDown: string = "DOWN"; break; - case SWT.MouseMove: string = "MOVE"; break; - case SWT.MouseUp: string = "UP"; break; - } + String string = switch (e.type) { + case SWT.MouseDown -> "DOWN"; + case SWT.MouseMove -> "MOVE"; + case SWT.MouseUp -> "UP"; + default -> "Unknown"; + }; string +=": button: " + e.button + ", "; string += "stateMask=0x" + Integer.toHexString (e.stateMask) + stateMask (e.stateMask) + ", x=" + e.x + ", y=" + e.y; if ((e.stateMask & SWT.BUTTON1) != 0) string += " BUTTON1";