Bug 566389 - [12] Convert if statement to switch expression
Summary: [12] Convert if statement to switch expression
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.17   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-26 02:14 EDT by Sarika Sinha CLA
Modified: 2020-08-26 03:22 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sarika Sinha CLA 2020-08-26 02:14:26 EDT
Similar to Bug 545342, it will be good to have a quick assist to convert if statement to switch expression.

public static void foo(int num) {
			int res;
			if (num == 100) {
				res = 1;
			} else if (num == 200) {
				res = 2;
			} else if (num == 300 || num == 3000) {
				res = 3;
			} else if (num == 400) {
				res = 4;
			} else {
				res = -1;
			}
		}
	
		public static void foo1(int num) {
			int res= switch (num) {
			case 100-> 1;
			case 200-> 2;
			case 300,3000-> 3;
			case 400-> 4;
			default -> -1;
			};
		}