Default argument like c++

is there a way so i can write default argument in processing like c++?
in c++, for example:

void test(a=100)
{
ā€¦ //some function that print value of a
}

so, when we call the function of test, if we dont passed value to that function, it will print 100
for example:
test() //print 100
test(200) //print 200

1 Like

yes, looks little bit stupid, but works:

void setup() {
  test();
  test(200);
}

void test(){
 test(100);
}
void test(int a){
  println(a);
}

shows:

100
200
5 Likes

Java does not have built-in default arguments.

@kll demonstrated one approach ā€“ method overloading, in which one signature has no arguments, and calls the second signature while supplying the default argument.

There are other approaches. One is to test for null and, if null, assign a default value. Then the no-arg form of a method call is foo(null). Another approach is to use varargs, and likewise check if each arg is present, and if not, assign its default. Another is to use the Builder pattern, in which each optional argument is a method.

A good summary of six approaches to default handling is in this answer:

5 Likes