zoukankan      html  css  js  c++  java
  • Dynamic typing 动态类型

    https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/DynamicTyping.html#//apple_ref/doc/uid/TP40008195-CH62-SW2

    A variable is dynamically typed when the type of the object it points to is not checked at compile time. Objective-C uses the id data type to represent a variable that is an object without specifying what sort of object it is. This is referred to as dynamic typing.

    Dynamic typing contrasts with static typing, in which the system explicitly identifies the class to which an object belongs at compile time. Static type checking at compile time may ensure stricter data integrity, but in exchange for that integrity, dynamic typing gives your program much greater flexibility. And through object introspection (for example, asking a dynamically typed, anonymous object what its class is), you can still verify the type of an object at runtime and thus validate its suitability for a particular operation. 

    The following example illustrates dynamic typing using a heterogeneous collection of objects:

    NSArray *anArray = [NSArray arrayWithObjects:@"A string", [NSDecimalNumber zero], [NSDate date], nil];
    NSInteger index;
    for (index = 0; index < 3; index++) {
        id anObject = [anArray objectAtIndex:index];
        NSLog(@"Object at index %d is %@", index, [anObject description]);
    }

    The object pointed to by the variable at runtime must be able to respond to whatever messages you send to it; otherwise, your program throws an exception. The actual implementation of the method invoked is determined using dynamic binding.

    The isa Pointer

    Every object has an isa instance variable that identifies the object's class. The runtime uses this pointer to determine the actual class of the object when it needs to.

  • 相关阅读:
    cbitmap 获取RGB
    存稿
    VC单选按钮控件(Radio Button)用法(转)
    MFC文档视图中窗口切换 (2012-05-11 18:32:48)
    MFC 结束线程
    vs2010调试运行时弹出对话框:系统找不到指定文件
    fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.
    自定义消息
    数据分析与可视化--matplotlib
    数据分析与可视化--pandas
  • 原文地址:https://www.cnblogs.com/feng9exe/p/7334375.html
Copyright © 2011-2022 走看看