Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!shadooby!accuvax.nwu.edu!nucsrl!gore!jacob From: jacob@gore.com (Jacob Gore) Newsgroups: comp.sys.next Subject: Re: Deferred methods and strong typing Message-ID: <130009@gore.com> Date: 7 Jul 89 07:42:52 GMT References: <130007@gore.com> Reply-To: jacob@gore.com (Jacob Gore) Organization: Gore Enterprises Lines: 37 / comp.sys.next / andyn@stpstn.UUCP (Andy Novobilski) / Jul 6, 1989 / > One piece of information missing is the declaration of 'anInstanceOfB'. > The warning will be given by the compiler if 'anInstanceOfB' is declared > type 'id'. This is because the compiler sees both interface files and > the fact the programmer has deferred binding until runtime (type id). The > compiler then choses the first interface as the default (notice the order > of @interface statements based on "#import" ordering). > > Correct type information can be given to the compiler by: This is the one I used: > 2) Declaring anInstanceOfB to be type B: > B *anInstanceOfB; That is where the error happened. I don't think the compiler should have chosen the 'someMethod' declared in class A over the one declared in class B. If I left 'someMethod' as type id in both the subclass (B) and the superclass (A), the subclass's method would overrule the superclass's method of the same name (the essense of Objective C's method inheritance mechanism, right?). However, once type information is provided for the subclass and the superclass, the compiler decides that they are not the same method at all, and proceeds to choose the first one it encounters, which, by convention (since a subclass imports its superclass's interface), is the superclass's method. Not nice. > 1) Typing the method: > [(B *)anInstanceOfB someMethod]; This should not be necessary. Strong typing should not break the inheritance chain. For now, I declare 'someMethod' in class B as returning (A*) instead of (B*), but hey... something is wrong here! -- Jacob Gore Jacob@Gore.Com {nucsrl,boulder}!gore!jacob