🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18473

Re: Object Oriented Nightmare??

#18473
From: Ken Chan
Date: Wed, 10 Jun 1998 00:00
38 lines
1838 bytes
Gerry Mantha wrote:

> It turns out that I
> have to override the print method in the SubInterface interface with:
> public void print(SubParm subParm);

I'd say that is an overload, not an override, because that is a different 
method signature; you're not "replacing" print(SuperParm), you're adding 
print(SubParm).

> Now, why must I have to explicitly override this method?  It's like Java
> automatically casts my interface and the parameter to the super just because
> print() is only defined in the SuperInterface!

My guess is that because you declared the object as a SubInterface:

  SubInterface subInterface = new SubClass();

the compiler searched that interface for a suitable method, and came up 
with one -- print(SuperParm). If you changed the declaration to:

  SubClass subInterface = new SubClass();

that would call print(SubParm) -- without you having to declare it in 
SubInterface -- because it is more specific; IOW, it works the way you 
think it should.

Going back to your original declaration, if you declare the field as a 
SubInterface, you cannot call a method defined in SubClass simply because 
that class implements that interface. You may only call methods in that 
interface and its ancestors. 

You may want to check out section 15.11 in the Java Language Spec.

-- 
//Ken@Inprise
<Please follow-up to newsgroup; do not reply to email>
Technical Details
Message-ID: <MPG.fe8c9a6386ce0e9899a6@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6lkfet$7hp9@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,cd8f0d1615c6e645
X-Google-Attributes: gidf74b3,public
From: supportinfo@borland.com (Ken Chan)
Subject: Re: Object Oriented Nightmare??
Date: 1998/06/10
Message-ID: <MPG.fe8c9a6386ce0e9899a6@forums.borland.com>
X-Deja-AN: 361538904
References: <6lkfet$7hp9@forums.borland.com>
Organization: Borland
Newsgroups: borland.public.jbuilder.java.language