Parameter with default value in Java

Asked

Viewed 19 times

1

In other languages, such as javascript, it is allowed to make a function by passing a parameter with a default value, as in the following structure:

function myFunction(value = true){
    //alguma ação
}

I tried to do the same with Java, only it’s not allowed.

public void myFunction(Boolean value = true) {
    //alguma ação
}

Does anyone know why or if there’s any alternative way?

  • True, I had not found it before. I will delete the question!

  • 2

    No excludes, duplicates are good for the site. Mainly because your question uses different terms, now if someone looks for what you asked will be able to find the answer in the other question...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.