Specifying default values in functions
If you come from the Java world, you might remember that we can't specify a default value to methods. This means that we can't do something like this in Java:
public void foo(int a, int b=10){ }
We need to write two methods for it, and it is known as method overloading:
public void foo(int a){ } public void foo(int a, int b){ }
Also, suppose you have a function with three different kinds of parameters, such as these:
public void foo (int a,double b, String c){ }
Then you'll have seven instances of method overloading:
public void foo (int a,double b, String c), public void foo (int a,double b) , public void foo (double b, String c), public void foo (int a, String c), public void foo (int a), public void foo (double b), public void foo (String c)
Kotlin provides you with default values in the methods by which you can prevent an insane amount of method overloading. Some people might say, "Hey, why don't we use the builder pattern instead of method overloading...