Skip to content

3.3. Method Overloading ​

Java:

java
public class Demo {

    public void draw(String text) { }

    public void draw(Shape shape) { }

    /* Method overloading + chaining for convenience methods with less arguments */

    void f(int x, String s, double z) { }

    void f(int x, String s) {
        f(x, s, 0.5);
    }

    void f(int x) {
        f(x, "hello");
    }
}

Vala: no method overloading, use different names instead or default values for arguments

vala
public class Demo : Object {

    public void draw_text (string text) {
    }

    public void draw_shape (Shape shape) {
    }

    /* Method with argument default values */
    void f (int x, string s = "hello", double z = 0.5) {
    }
}

Vala does not support method overloading because libraries written in Vala are intended to be usable by C programmers as well with meaningful function names.