| Thread overview | |||||
|---|---|---|---|---|---|
|
July 12, 2013 Final class | ||||
|---|---|---|---|---|
| ||||
Are all methods in final class non-virtual or must be explicity marked as a final too? | ||||
July 12, 2013 Re: Final class | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On Friday, July 12, 2013 07:03:07 Daniel Kozak wrote:
> Are all methods in final class non-virtual or must be explicity marked as a final too?
They're virtual if they override base class functions, but they're definitely all final. So, the compiler _should_ optimize the functions in a final class which don't override anything so that they're non-virtual. However, I'm not sure that there's actually any guarantee that final methods which don't override anything will actually be made non-virtual. It's an optimization based on the fact that the compiler can determine that it can be made non- virtual rather than it explicitly being made non-virtual by the programmer, so the compiler might not do it. It _should_, but I'm not sure that it's guaranteed to.
- Jonathan M Davis
| |||
July 12, 2013 Re: Final class | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Friday, 12 July 2013 at 05:13:44 UTC, Jonathan M Davis wrote:
> On Friday, July 12, 2013 07:03:07 Daniel Kozak wrote:
>> Are all methods in final class non-virtual or must be explicity
>> marked as a final too?
>
> They're virtual if they override base class functions, but they're definitely
> all final. So, the compiler _should_ optimize the functions in a final class
> which don't override anything so that they're non-virtual. However, I'm not
> sure that there's actually any guarantee that final methods which don't
> override anything will actually be made non-virtual. It's an optimization
> based on the fact that the compiler can determine that it can be made non-
> virtual rather than it explicitly being made non-virtual by the programmer, so
> the compiler might not do it. It _should_, but I'm not sure that it's
> guaranteed to.
>
> - Jonathan M Davis
Thanks
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply