[swift-users] Usage of final let?

Azuan alienxp03 at gmail.com
Mon Jun 13 21:05:34 CDT 2016


I do undertand the difference. But would someone be kind enough to enlighten me with the correct example on how would you override a let variable in it’s subclasses and that you can prevent it by using the final modifier?


Regards,
Azuan

On 14 June 2016 at 9:59:16 AM, Jens Alfke (jens at mooseyard.com) wrote:


On Jun 12, 2016, at 10:43 PM, Azuan via swift-users <swift-users at swift.org> wrote:

Read in docs, saying that by using final on variables, you can’t override it in it’s subclass. Using `final var` makes sense to me. But what is the purpose of using `final let` since by using `let`, it is already an immutable variable anyway.

Immutable isn’t the same as non-overridable. Immutable just means that its value in a single instance can’t be changed after initialization. But there’s nothing stopping you from creating a subclass that has a different value for that constant.

—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160614/f5d1078b/attachment.html>


More information about the swift-users mailing list