0%

在比较之前,你应该了解以下知识:

  1. Objcetive-C的函数调用机制
  2. Objective-C的对象模型
  3. Objective-C的动态特性

在阅读完毕,了解知道Objective-C 中的 Message、Object、Class、MetaClass、Method(SEL-IMP) 的重要概念后,现在开始比较!

下面是来自 WIKI 的对 static method 的定义

Static methods neither require an instance of the class nor can they implicitly access the data (or this, self, Me, etc.) of such an instance. A static method is distinguished in some programming languages with the static keyword placed somewhere in the method’s signature.

In statically typed languages such as Java, static methods are called “static” because they are resolved statically (i.e. at compile time) based on the class they are called on and not dynamically as in the case with instance methods which are resolved polymorphically based on the runtime type of the object. Therefore, static methods cannot be overridden.

从定义可以看出,Objective-C 的 class method 根本不是 static method,而实际上,Objective-C 也不存在 static method!(尽管 class method 因为用法而看似 static method,但它们是有本质的差别的。)

那么它们的区别是?(出于好奇心,我们假设下 Objective-C 中有 static method → →)

Read more »