Question

On this documentation page of interfaces on dlang.org, it says interfaces must implement final methods. What are final methods? The keyword doesn't seem to be mentioned on any other page.

There is this page I found, but it seems to be a remain from the ancient D1.

Is a final function simply a function returning an immutable result? Does the keyword even still exist?

Était-ce utile?

La solution 2

A final function is one that cannot be overridden in a child class (the opposite of a virtual function).

All templates are final, so any template in an interface must have a function body or else you'll get a linker error.

Autres conseils

From Virtual Functions:

Functions marked as final may not be overridden in a derived class, unless they are also private.

beside what the other answers have said:

an interface may specify a final function and implement it directly

interface Foo{
    int bar();

    final int doublefoobar(){
        return bar()*2;
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top