Path: csiph.com!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: Wed, 12 Jul 2017 16:23:50 -0000 (UTC) Organization: A noiseless patient Spider Lines: 21 Message-ID: References: <46334961-cc18-491f-828c-32e7401c7832@googlegroups.com> Reply-To: avl@logic.at Injection-Date: Wed, 12 Jul 2017 16:23:50 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="371c9d5ac9ac4782c73d2db3efc43c4d"; logging-data="15845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+w0ecVLiwkfnziwJy4CH7D" User-Agent: slrn/1.0.2 (Linux) Cancel-Lock: sha1:9IVeiblbbFDQVrII2a76gKwtrxI= Xref: csiph.com comp.lang.java.programmer:36865 Jerry Stuckle wrote: > Nope. In the strictest sense is is NOT a valid derived class. The > rules given for Employee were that wage must be >= minimum wage. The > rules for Manager do not include that restriction. Therefore it is an > invalid inheritance - no matter what you name them. Welcome to the topic of covariant versus contravariant types. If I have a square (e.g. a unit square), then this square *is* also *a* rectangle. If I have a class Rectangle and a class Square, then Square is a subclass of Rectangle (as every square is obviously also a rectangle). But then Rectange may have a method to *set* both side lengths. But Square would not allow to set two different lengths. Question: is a Square a Rectangle, or is a Rectange a Square? Answer: depends... PS: that's also why Java generics offer for certain uses.