Re: Why the need for the id type?
Re: Why the need for the id type?
- Subject: Re: Why the need for the id type?
- From: Wagner Truppel <email@hidden>
- Date: Tue, 19 Jun 2007 01:17:19 +0200
On 19 Jun 2007, at 01:10, Oleg Kibirev wrote:
On Jun 18, 2007, at 2:57 PM, Chris Williams wrote:
On 6/18/07 2:28 PM, "Greg Titus" <email@hidden> wrote:
In this code:
id foo;
[foo someRandomMethod];
As long as -someRandomMethod exists _anywhere_ on any class, it will
work. Importantly, -someRandomMethod can be implemented on many
classes which DO NOT share any common root class, and the code will
work.
Important distinction -- it will COMPILE. I may NOT work. In
fact, it
could fail in a very ugly fashion at runtime if in fact foo is not
an object
with -someRandomMethod by that point.
I wouldn't say throwing an exception that you can examine in your
code or debugger is "failing in very ugly fashion". If you are not
sure that all possible kinds of foo will implement the method, just
use:
if ([foo respondsToSelector(someRandomMethod)])
[foo someRandomMethod];
The equivalent Java code is huge.
Oleg
Huge indeed. And that's precisely the reason why I was talking about
a transparent mechanism in the fictitious language I was proposing in
one of my previous messages.
Wagner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden