Skip to main content

Default Parameter Values in Java

Published: 2018-08-10 • Last updated: 2021-05-03

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.