What is the difference between final Class and Class?

Classes marked with final can not be overridden.


Why should one care at all whether class can or can’t be overridden?

There are two things to consider:

  1. As an API designer/developer, you might have a class in your Framework that can be abused or misused when subclassed. final prevents class to be subclassed—mission accomplished. You can also use final to mark methods, properties, and even subscripts of non-final classes. This will have same effect, but for particular part of the class.
  2. Marking class as final also tells Swift compiler that method should be called directly (static dispatch) rather than looking up a function from a method table (dynamic dispatch). This reduces function call overhead and gives you extra performance. You can read more on this on Swift Developer Blog.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)