Skip to main content

Default parameter values in Java

Published: 2018-08-10 • Lastmod: 2019-09-12

I’m used to C#, so if I want a parameter to have a default value, it can be done like this.

private static void sayHi(string message = "Hi") 

But what about Java? It can be done as well, and one way is to use method overloading.

private static void sayHi(String message) {

private static void sayHi() {

Shoutout to this stackoverflow post.

Next: Maui trip
Previous: MacBook tweaks