Default parameter values in Java

August 10, 2018

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") 
{
    Console.WriteLine(message);
}

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

private static void sayHi(String message) {
    System.out.println(message);
}

private static void sayHi() {
    sayHi("Hi");
}

Shoutout to this stackoverflow post.