interface final members

Mantis mail.mantis.88 at gmail.com
Tue Feb 21 05:15:31 PST 2012


21.02.2012 14:46, Joshua Reusch пишет:
> interface I {
> final int foo(I other, int a, int b) {
> return other.foo(a,b) + a*b;
> }
> int foo(int a, int b);
> }
>
> class A : I {
> int foo(int a, int b) {
> return a*b;
> }
> }
>
> void main() {
> A a = new A;
>
> a.foo(5,5);
> a.I.foo(a, 5,5);
> a.foo(a, 5,5); //line 22
> }
> ---------
> $ rdmd interface_final_test
> interface_final_test.d(22): Error: function interface_final_test.A.foo 
> (int a, int b) is not callable using argument types (A,int,int)
> interface_final_test.d(22): Error: expected 2 arguments, not 3 for 
> non-variadic function type int(int a, int b)
> ---------
>
>
> Why do I need to write a.I.foo instead of a.foo to call the final 
> method of the interface ?
>
> Thank you, Joshua
>
>

I can't comment on the behaviour, but you may find this workaround useful:

class A : I {
alias I.foo foo;
int foo(int a, int b) {
return a*b;
}
}


More information about the Digitalmars-d-learn mailing list