Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: How to assign an object to another in it method? Date: Thu, 13 Jul 2017 10:08:52 -0000 (UTC) Organization: A noiseless patient Spider Lines: 36 Message-ID: References: <46334961-cc18-491f-828c-32e7401c7832@googlegroups.com> Reply-To: avl@logic.at Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 13 Jul 2017 10:08:52 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="891ec2ce37e0ba46fd2b2385f5ad4a6c"; logging-data="3907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uYzbTyYZtRtzvZQMgeBK1" User-Agent: slrn/1.0.2 (Linux) Cancel-Lock: sha1:ccx2EH7GAGf3l6NaUaSzmqDKGnY= Xref: csiph.com comp.lang.java.programmer:36877 Jerry Stuckle wrote: > On 7/11/2017 9:49 PM, Arne Vajhøj wrote: >> My post does not contain "valid values". >> Your post containa "valid values". > Sorry, you are correct. It was Andreas who brought up the default > values. My mistake - I didn't read closely enough. The sub-topic of "default values" was what triggered me into entering the discussion. I brought up the problem(imho) of overriding methods with changed default values for arguments, which in C++ are static type matter (non-polymorphic). Apparently this triggered someone else to think that if I even want to use a different default value in the override, then "obviously" the original would necessarily be inappropriate or "invalid" for the subclass. I think that's how validity entered this thread. PS: my Manager/Employee adaption did not yet have a minimumWage constraint. If it had one, then Manager would probably have a "more constraining" one. I.e.: his minimum wage would be even higher. (Assuming that the Manager is still an Employee, too, and not already the owner of the company.) Going back to Java and the Rectangle/Square example: What would be Square's appropriate way to deal with the setDimensions(int height,int width) inherited from Rectangle? Apparently it would need to still offer it and thus introduce a new potential for runtime-errors with currently no way to have already the compiler warn about "square.setDimensions(1,2)" being fishy. 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.