Java Enhanced Switch

A switch statement allows the application to have multiple possible execution paths based on the value of a given expression in runtime.

The evaluated expression is called the selector expression which must be of type char, byte, short, int, Character, Byte, Short, Integer, String, or an enum.

In Java 14 a neat language feature was added, the switch statement was enhanced. Here is a simple example where I return a string based upon the specified Colour enum:

For more details on the enhanced switch statement, please see this excellent post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s