Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: How to assign an object to another in it method? Date: Thu, 13 Jul 2017 11:35:30 -0000 (UTC) Organization: A noiseless patient Spider Lines: 25 Message-ID: References: <46334961-cc18-491f-828c-32e7401c7832@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 13 Jul 2017 11:35:30 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="a030be9b927e55fdbc797641d56ce0cb"; logging-data="24076"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XnxCgtQfPuJHnXyxaGepKQ0UfYjPdQuI=" User-Agent: Pan/0.141 (Tarzan's Death; 168b179 git.gnome.org/pan2) Cancel-Lock: sha1:3EpO+3PWl+CNdSNCRWXm/Fe5Dok= Xref: csiph.com comp.lang.java.programmer:36881 On Thu, 13 Jul 2017 10:08:52 +0000, Andreas Leitgeb wrote: > Ideally, a subclass should be allowed to "remove" methods in a way that > the compiler could preempt some mistakes: "If you already know you're > dealing with a Square, then rather use Square's setDimension(int length) > instead of the inherited setDimension(int,int)". Obviously the compiler > couldn't catch cases like ((Rectangle)square).setDimensions(1,2), so not > all runtime errors can be prevented at compile time, but at least some. > In this case why wouldn't you override Rectangle.setDimensions() with a variant that throws an exception if the two dimensions differ as well as adding the trivial method: public void setDimensions(int size) { super.setDimensions(size, size); } for convenience? -- martin@ | Martin Gregorie gregorie. | Essex, UK org |