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 00:06:11 +0200
What if I have a method like -objectEnumerator on NSArray, NSSet,
NSDictionary, which don't share a common root class other than
NSObject, which does not implement that method. In Java, you have
nothing to cast to. How would you write generic code that can
enumerate over anything enumerable?
Java interfaces solve that problem, no?
The solution in these other languages is either some sort of meta-
programming (i.e. templates) or to add a new superclass (like a
theoretical "NSEnumerable") which gives you something in common and
something to cast to.
Interfaces.
Perhaps I should be a bit more specific.
Imagine that I decided to create my own language, fashioned closely
to java but with a few whistles and bells added to Object. More
specifically, any Object instance would know how to do introspection
much like NSObject, with methods to answer questions like "does the
object respond to such and such message", "what is the object's
superclass", and so on. (All of that can be done in java, of course,
but one has to deal with all the exceptions and so on. I'm talking
about a transparent process here, where the developer need not worry
about any of that.)
Of course, the compiler can issue warnings for unanswerable messages,
just as XCode's does for Obj-C. Moreover, the runtime system
associated with the language would take full advantage of those
facilities, determining at runtime whether an object can or cannot
respond to a given message. If not, the message would be ignored.
It seems to me that I would have *all* of the behavior of Objective-
C, without id. The root class in my language would play the role of
Obj-C's id.
It's for this reason that it seems to me that id is nothing more than
a root class in disguise. Yes, I know, id is not a class (I suppose
my abuse of language in previous messages led people to think that I
was claiming id to be a class). But it might as well be, since it
behaves like a smart root class.
"Thank you" to all the many people who answered my question.
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