문제

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?

도움이 되었습니까?

해결책 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.

다른 팁

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;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top