What does the construct x = x || y mean?

It means the title argument is optional. So if you call the method with no arguments it will use a default value of “Error”. It’s shorthand for writing: This kind of shorthand trick with boolean expressions is common in Perl too. With the expression: it evaluates to true if either a or b is true. So if a is true you don’t need to check b at all. This … Read more

Java optional parameters

There are several ways to simulate optional parameters in Java: Method overloading.void foo(String a, Integer b) { //… }void foo(String a) { foo(a, 0); // here, 0 is a default value for b }foo(“a”, 2); foo(“a”); One of the limitations of this approach is that it doesn’t work if you have two optional parameters of … Read more

Java optional parameters

There are several ways to simulate optional parameters in Java: Method overloading.void foo(String a, Integer b) { //… }void foo(String a) { foo(a, 0); // here, 0 is a default value for b }foo(“a”, 2); foo(“a”); One of the limitations of this approach is that it doesn’t work if you have two optional parameters of … Read more