urandom0
urandom0

Reputation: 63

What is difference between method hiding and without "new" keyword?

This is the method hiding:

class SuperClass : GLib.Object {
    public void method1() {
        stdout.printf("SuperClass.method1()\n");
    }
}

class SubClass : SuperClass {
    public new void method1() {
        base.method1();
        stdout.printf("SubClass.method1()\n");
    }
}

And same code without "new" keyword:

class SuperClass : GLib.Object {
    public void method1() {
        stdout.printf("SuperClass.method1()\n");
    }
}

class SubClass : SuperClass {
    public void method1() {
        base.method1();
        stdout.printf("SubClass.method1()\n");
    }
}

What is the difference between these?

edit: in the generated C code absolutely there is no difference, so I think the compiled binary is same.

Upvotes: 1

Views: 61

Answers (1)

avojak
avojak

Reputation: 2360

There isn't any functional difference, however being explicit with the new keyword is ideal and avoids the compiler warning.

Upvotes: 0

Related Questions