Pregunta

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?

¿Fue útil?

Solución 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.

Otros consejos

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;
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top