As far as I know static funcs are statically dispatched and final class funcs are also statically dispatched (since final funcs cannot be overriden - just like static funcs). But then what exactly is the difference. Is there any at all?
Asked
Active
Viewed 1,116 times
1
-
1Possible duplicate of [What is the difference between static func and class func in Swift?](https://stackoverflow.com/questions/25156377/what-is-the-difference-between-static-func-and-class-func-in-swift) – Papershine Sep 16 '18 at 05:20
-
no.. that is class func, not final class func :) – angshuk nag Sep 16 '18 at 05:34
1 Answers
4
Just because a final
class function can't be overridden doesn't mean it's statically dispatched. A final class function be override a superclass non-final class function. Such a method call must be dynamically dispatched.
static
is merely an alias for final class
. They behave the same:
class C1 { class func foo() {} }
class C2: C1 { override final class func foo() {} }
class C3: C1 { override static func foo() {} }

Alexander
- 59,041
- 12
- 98
- 151
-
-
4"Static" is an alias for "final class": https://stackoverflow.com/a/29206635/1187415, so there should be no difference. – Martin R Sep 16 '18 at 07:39
-
-
So both static and final class functions can be safely concluded to be Statically dispatched – angshuk nag Sep 17 '18 at 13:04
-
1@angshuknag No, they're both dynamically dispatched. Otherwise, how would overloading work? – Alexander Sep 17 '18 at 17:11