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: Greg Titus <email@hidden>
- Date: Mon, 18 Jun 2007 15:16:57 -0700
On Jun 18, 2007, at 3:06 PM, Wagner Truppel wrote:
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?
Yes, or Objective-C protocols. But you are still casting to an
interface. You are still forced to rebuild your class hierarchy any
time this comes up (adding "implements Enumerable" to all your
classes). You are essentially adding an implementation-less
additional superclass. That adds complexity.
But let's use a more complicated example, then. How would you
implement the NSUndoManager -prepareWithInvocationTarget: method
without an "id" type to return? In this case there is no possible
interface because there is no previously specified set of valid
method names. You can really and truly call _any_ method on the
return value. Including methods that never existed when NSUndoManager
was compiled.
(Feel free to look up the NSUndoManager documentation and ask
questions if you don't understand why this is so.)
- Greg
_______________________________________________
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