Objective-C uses dynamic binding: method calls are resolved at runtime.
Fine
And using dot notation really comes down to a method call
But why then I can not do something like this:
#import <Foundation / Foundation.h>
int main (int argc, const char * argv []) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Intercept the exception
@try
{
@throw [NSException
exceptionWithName: @ "Exception named ME!"
reason: @ "Because i wanted to"
userInfo: nil];
}
@catch (id exc) // pointer to an exception object?
{
// NSLog (@ "% @:% @ \ n", exc.name, exc.reason); // ILLEGAL: Request for member
// 'name' in something not a structure or union. .
// If objective-c uses dynamic binding, and dot notation
// boils down to calling the getter, then
// WHY do I have to cast to the concrete type here?
// Only works if I cast to the concrete type NSException *
NSException * nexc = (NSException *) exc;
NSLog (@ "% @:% @ \ n", nexc.name, nexc.reason);
}
[pool drain];
return 0;
}
When I hear βdynamic binding,β I think βit should behave like a scripting language,β and I wonder how inflexible Objective-C seems compared to a scripting language like JavaScript.
objective-c dynamic-binding
bobobobo
source share