Java/Android Default Arguments


I'm fairly new to Java and even more recent to Android development. Confused for one moment

How to set arguments with a default value in a method? It is not very pleasant to produce a ton of overloads for all occasions.


There is no such possibility. To achieve the desired effect, do this:

void init(int a, int b, int c) {

void init(int a, int b) {
    // Значение параметра с по умолчанию 10
    init(a, b, 10); 

void init(int a) {
    // Значение параметра с по умолчанию 10, b по умолчанию 20
    init(a, 20, 10);

That is, they overload the method several times (for each default parameter).

Scroll to Top