Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Confusing interface Date: Fri, 7 Jul 2017 15:27:16 -0400 Organization: A noiseless patient Spider Lines: 35 Message-ID: References: <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 19:23:34 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="ce67c2b27e35227899c522f2fd53802e"; logging-data="5615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+P+CJqJSNv31sfsQZjP94n" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:QPdn04Cs5kFBcYAKa185Wf0jNj8= Xref: csiph.com comp.lang.java.programmer:36824 On 7/7/2017 3:00 PM, Eric Douglas wrote: > On Friday, July 7, 2017 at 2:50:49 PM UTC-4, Eric Sosman wrote: >> Cloning a B gives whatever A's clone() implementation returns. >> That might be a B, or an A, or a C, or an Object -- it's entirely >> up to clone(). >> >> ... but what has any of this to do with overriding or failing >> to override? Did you work through the example I gave? Did it >> behave as you expected (and/or did your expectations adjust to >> its behavior)? >> > > That is the override, or lack of, and it sounds like you're saying what I suspect. > DefaultMutableTreeNode implements Cloneable, so if I extend it I must implement Cloneable, or else create a clone() method that simply throws an exception. Otherwise someone could clone my class and get an instance of DefaultMutableTreeNode, when they should expect it to return an instance of the extending class. "To extend it I must implement Cloneable ..." Simply by extending you *already* implement Cloneable. If you're happy with the clone() implementation in the superclass, just stay happy and move on to other matters. If you're unhappy, override. Observe that the caller of clone() receives an Object reference, not a DefaultMutableTreeNode or MyCustomTreeNode reference. The referred-to instance's type is something you'll need to know from the documentation, or infer by reflection. But this still has nothing to do with your original question, which was (boiled down to essentials): "If a superclass has a method that takes a Thing parameter, why can't I override it with a method taking a SubclassOfThing parameter?" But you're now trying to pose the same question about clone() -- and since clone() takes zero count them zero parameters, the question has no meaning. -- esosman@comcast-dot-net.invalid Twelve hundred ninety-three days to go.