[Issue 2050] interfaces should allow final methods with body

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 4 08:58:11 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2050





------- Comment #11 from andrei at metalanguage.com  2009-04-04 10:58 -------
(In reply to comment #9)
> (In reply to comment #0)
> This seems to break composability:
> 
> interface I1 { final int foo() {return 1;} }
> interface I2 { final int foo() {return 2;} }
> 
> class A: I1, I2 {}
> 
> Whose foo does A choose? And how is it resolved? (given you can't drop one of
> the interfaces).

I think that's an ambiguity. It might be busted by having A write e.g. alias
I1.foo foo;

> And consider
> 
> class B: I1, I2 { final int foo() {return 3;} }
> B b = new B();
> I1 i1 = b;
> I2 i2 = b;
> assert( i1.foo == 1 );
> assert( i2.foo == 2 );
> assert(  b.foo == 3 );

A good use of final functions is to enable the non-virtual interface idiom. The
point of that idiom is partially that you cannot override final functions in
interfaces.


-- 



More information about the Digitalmars-d-bugs mailing list