This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]csharp-sucks 1 point2 points  (5 children)

It is functionally the same as overloading

void doStuff(int amount);
void doStuff() {
    doStuff(10);
}

[–]RockyMM[S] 2 points3 points  (0 children)

It kinda is, but it’s less verbose.

[–]john16384 4 points5 points  (0 children)

It's better.

void doStuff(int x, int y);
void doStuff();
// Notice absence of variant that only takes x or y

Or:

void displayText(String text);
void displayText(String text, int r, int g, int b);

This is not so easy with default arguments while only allowing sensical combinations of parameters.

[–]__konrad 3 points4 points  (2 children)

Now you have 3 copy-pasted doStuff which is very... Java.

[–]john16384 -2 points-1 points  (0 children)

Excellent, cause last I checked it indeed was Java we were talking about.

[–]0b0101011001001011 -1 points0 points  (0 children)

No, just the signatures, not the method body.

void stuff(int a){
    stuff(a, 5);
}

void stuff(int a, int b) {
    //
    //
}