Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36814
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Confusing interface |
| Date | Fri, 7 Jul 2017 11:26:54 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 57 |
| Message-ID | <ojo90v$l5f$1@dont-email.me> (permalink) |
| References | <cd610d1e-ecc4-443b-b346-eb8847b22b74@googlegroups.com> <ojo339$fa$1@dont-email.me> <0175016c-5ab9-4867-a9d1-7c43907e4427@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Fri, 7 Jul 2017 15:23:11 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="ce67c2b27e35227899c522f2fd53802e"; logging-data="21679"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Vs2LuE0UGjWAbGBHQBIKa" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
| In-Reply-To | <0175016c-5ab9-4867-a9d1-7c43907e4427@googlegroups.com> |
| Content-Language | en-US |
| Cancel-Lock | sha1:+fS5dbYS7JgGXK50AcbH7HPtRo8= |
| Xref | csiph.com comp.lang.java.programmer:36814 |
Show key headers only | View raw
On 7/7/2017 10:37 AM, Eric Douglas wrote:
> On Friday, July 7, 2017 at 9:46:10 AM UTC-4, Eric Sosman wrote:
>> Because `setParent(MyCustomTreeNode newParent)' does not override
>> the setParent() method of the superclass. You can write the method
>> with the signature you like, but it's not an override. Consider:
>>
>> MyCustomTreeNode parent = ...;
>> MyCustomTreeNode child = ...;
>> child.setParent(parent);
>>
>> So far, all is well and behaves as you intend. Next, however:
>>
>> DefaultMutableTreeNode kidnapper = ...;
>> child.setParent(kidnapper);
>>
>> Question: Which setParent() method runs, the one in your class or the
>> one in the superclass? Right you are, it's the superclass' method --
>> which means your class has not overridden it.
>>
>
> but the setParent method in DefaultMutableTreeNode accepts a MutableTreeNode, not a DefaultMutableTreeNode. So I would think if you override that in MyCustomTreeNode to accept a MyCustomTreeNode, then if child is an instance of MyCustomTreeNode, it should throw an error on setParent if the parameter is not an instance of MyCustomTreeNode.
Yes, DefaultMutableTreeNode::setParent accepts a MutableTreeNode.
*Any* MutableTreeNode, including a DefaultMutableTreeNode or a
MyCustomTreeNode or a FoundItSomewhereOnStackOverflowTreeNode or ...
Your non-overriding method accepts only a MyCustomTreeNode, not
any of the others.
Here's a pared-down version that avoids the complications of
interfaces and Swing; try it and see if you understand what's afoot:
class Super {
void doIt(Super s) {
System.out.println("Super::doIt");
}
}
class Sub extends Super {
void doIt(Sub s) {
System.out.println("Sub::doIt");
}
}
class Driver {
public static void main(String[] unused) {
Super sup = new Super();
sup.doIt(sup); // no surprises yet
Sub sub = new Sub();
sub.doIt(sub); // no surprises yet
sub.doIt(sup); // surprised?
sub.doIt((Super) sub); // how about now?
}
}
--
esosman@comcast-dot-net.invalid
Twelve hundred ninety-three days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 06:10 -0700
Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 09:45 -0400
Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 07:37 -0700
Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 11:26 -0400
Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 11:24 -0700
Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 14:50 -0400
Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 12:00 -0700
Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 15:27 -0400
Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 12:47 -0700
Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 16:25 -0400
Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 13:39 -0700
Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 17:43 -0400
csiph-web