November 18, 2004
I'm familiar with const from C/C++, and final from Java. How are const and final different from one another in D?  Is the only difference that final variables may be initialized in the constructor, and const variables can only be initialized by declaration?  Or is final only involved in preventing class inheritance?

Regards,
Garett


November 18, 2004
Garett Bass wrote:

> I'm familiar with const from C/C++, and final from Java. How are const and final different from one another in D?  Is the only difference that final variables may be initialized in the constructor, and const variables can only be initialized by declaration?

final doesn't apply to variables. Const applies to variables and means their initializers must evaluate to compile-time constants. See http://www.digitalmars.com/d/attribute.html

> Or is final only involved in preventing class inheritance?

yup. See the first section of http://www.digitalmars.com/d/function.html. It
seems legal to declare an entire class as final but I'm not sure it does
anything.

> Regards,
> Garett