The Java 17 release introduces Pattern Matching for switch as a preview language feature. Pattern matching allows case labels with patterns rather than just constants, which gives us more flexibility when defining conditions for switch cases.
How to perform a different action for each type of object, without using instance of?
Now the switch selector expression can be of any type.
Using pattern matching and sealed class, the compiler can check that all allowed subclasses are covered and there is no longer a need for a default case.
Guarded pattern allow us to perform additional checks.
The full implementation of this tutorial can be found over on GitHub.
In December of 2017 I was working on a Java EE web project from my startup.
One of the first things that needed to be defined was where to host the application.
After studying Heroku, Openshift, AWS and Google Cloud, I decided to use Docker containers on Google Cloud infrastructure.
Google Cloud with Docker container lets you use all the power of the Java EE stack. It has low prices, ease of configuration, scalability and platform independence.
As it was a private project, I chose to use Bitbucket because it has Git and pepilines to do the integrations with Google Cloud and Slack.
The following are the settings required to run the continuous integration and continuous deployment pipelines:
At the root of the Java project two files are required:
You must add three Environment variables:
Go to your repository settings in Bitbucket and navigate to Pipelines > Environment variables. Create a new variable named GCLOUD_API_KEYFILE and paste the encoded service account credentials in it.
Add a new variable called GCLOUD_PROJECT and set the value to the key of your Google Cloud project.
Add another variable called APP_NAME and set the name of your app.
In Pipelines you can configure the build schedule.