Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

final

Part of KeywordsCategory

Description

Shows the usage of the final keyword on a class.

Example

/* 
This example won't compile with either "final" compiled in: 
final.d(34): function toString cannot override final function toString  
*/ 


/+final+/ class A
{
    private char[] name;
    
    /+final+/ char[] toString()
    {
        return name;
    }
    
    this(char[] s)
    {
        name = s;
        printf("'%.*s' created\n", name);
    }
    ~this()
    {
        printf("'%.*s' destroyed\n", name);
    }
}


class B: A /+ If class A is final this wouldn't work. +/
{
    char[] name;

    char[] toString() /* If this method were final in class A, this would cause a compile error. */
    {
        return name;
    }

    this(char[] s)
    {
        super(s);
    }
    ~this()
    {
        printf("'%.*s' destroyed\n", name);
    }
}


void main()
{    
}

More Information

Apparently similar to Java's final.

Source

Link http://www.dsource.org/tutorials/index.php?show_example=74
Posted by jcc7
Date/Time Wed May 19, 2004 6:01 pm