Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36824

Re: Confusing interface

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 15:27:16 -0400
Organization A noiseless patient Spider
Lines 35
Message-ID <ojon3m$5ff$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> <ojo90v$l5f$1@dont-email.me> <c30448c3-8f2b-4eba-80c4-c395566dd970@googlegroups.com> <ojokuh$tqh$1@dont-email.me> <ad49ff16-7feb-46d7-82df-d13b22d69a90@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 <ad49ff16-7feb-46d7-82df-d13b22d69a90@googlegroups.com>
Content-Language en-US
Cancel-Lock sha1:QPdn04Cs5kFBcYAKa185Wf0jNj8=
Xref csiph.com comp.lang.java.programmer:36824

Show key headers only | View raw


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.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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